This markdown is for building models to test effects of land use and typhoons on acoustic indices and bird species detections. Modeling framework uses Bayesian models to test for effects of typhoons and land use (plus their interaction) on means and variabilities of acoustic indices and bird detections. Also tests land use effect on acoustic index resistance and recovery. Can test for spatial autocorrelation of model residuals and fit spatial error terms where needed.

Acoustic indices

acoustic index mean states

NDSI - negative change after typhoon

# get pre vs post data for comparison
dat_pre<-tidy.stability_AI %>%
  filter(Index %in% "NDSI" & response_variable %in% 'Pre_mean') 
dat_post<-tidy.stability_AI %>%
  filter(Index %in% "NDSI" & response_variable %in% 'Post_mean')
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
#names(df)[1] <- names(Landuse_1000)[1]
#df <- left_join(df, Landuse_1000, by = "site_id")

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse * Typhoon + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Trying to compile a simple C file
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
## Start sampling
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 7 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()
## No divergences to plot.

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 516dc2723972b0b4959c45f1ed5792b7.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                     mean se_mean    sd   2.5%    25%    50%
## b_Intercept                         1.45    0.00  0.23   0.99   1.30   1.45
## b_LanduseDeveloped                  0.37    0.00  0.36  -0.35   0.14   0.37
## b_TyphoonPost                      -0.52    0.00  0.13  -0.78  -0.61  -0.52
## b_LanduseDeveloped:TyphoonPost      0.06    0.00  0.21  -0.36  -0.08   0.06
## sd_Site_ID__Intercept               0.77    0.00  0.14   0.55   0.67   0.76
## phi                                54.10    0.07 15.76  27.75  42.79  52.59
## r_Site_ID[CHATANOP,Intercept]      -0.71    0.00  0.29  -1.28  -0.90  -0.71
## r_Site_ID[GENKAOP,Intercept]       -1.02    0.00  0.32  -1.65  -1.23  -1.02
## r_Site_ID[GESASHIOP,Intercept]      0.68    0.00  0.33   0.05   0.46   0.67
## r_Site_ID[HEIWAOP,Intercept]       -1.87    0.00  0.30  -2.46  -2.07  -1.87
## r_Site_ID[HENTONAOP,Intercept]      0.78    0.00  0.38   0.06   0.52   0.77
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.04    0.00  0.35  -0.63  -0.19   0.03
## r_Site_ID[KEMINFR,Intercept]        0.15    0.00  0.35  -0.53  -0.09   0.14
## r_Site_ID[KURASHIKIOP,Intercept]    0.75    0.00  0.33   0.11   0.53   0.74
## r_Site_ID[MANABIFR,Intercept]       0.29    0.00  0.35  -0.39   0.06   0.28
## r_Site_ID[NAGOFR,Intercept]         0.83    0.00  0.34   0.19   0.60   0.82
## r_Site_ID[NAKAGUSUKUFR,Intercept]   0.47    0.00  0.32  -0.15   0.25   0.46
## r_Site_ID[OISTFR,Intercept]         0.12    0.00  0.35  -0.55  -0.11   0.11
## r_Site_ID[OISTOP,Intercept]        -0.83    0.00  0.33  -1.47  -1.04  -0.83
## r_Site_ID[OKUFR,Intercept]         -0.15    0.00  0.34  -0.81  -0.37  -0.15
## r_Site_ID[OYAMAOP,Intercept]       -0.36    0.00  0.29  -0.94  -0.56  -0.37
## r_Site_ID[SEFAFR,Intercept]         0.73    0.00  0.33   0.10   0.50   0.72
## r_Site_ID[SENBARUOP,Intercept]     -0.16    0.00  0.30  -0.74  -0.36  -0.16
## r_Site_ID[SUEYOSHIFR,Intercept]     0.27    0.00  0.31  -0.33   0.06   0.27
## r_Site_ID[TAKEYANBARUF,Intercept]   0.05    0.00  0.35  -0.61  -0.18   0.05
## r_Site_ID[TAMAGUSUKUFR,Intercept]   0.57    0.00  0.33  -0.06   0.35   0.56
## r_Site_ID[TOUNANOP,Intercept]      -0.01    0.00  0.30  -0.60  -0.22  -0.02
## r_Site_ID[UEHARAFR,Intercept]      -0.45    0.00  0.30  -1.03  -0.65  -0.45
## r_Site_ID[YACHOOP,Intercept]       -0.60    0.00  0.29  -1.17  -0.79  -0.60
## r_Site_ID[YONAFR,Intercept]         0.63    0.00  0.37  -0.07   0.38   0.62
## lprior                            -12.49    0.00  0.46 -13.39 -12.80 -12.49
## lp__                               31.45    0.04  6.34  17.82  27.47  31.90
##                                      75%  97.5% n_eff Rhat
## b_Intercept                         1.60   1.92 31234    1
## b_LanduseDeveloped                  0.61   1.09 33341    1
## b_TyphoonPost                      -0.44  -0.26 73820    1
## b_LanduseDeveloped:TyphoonPost      0.20   0.48 73790    1
## sd_Site_ID__Intercept               0.85   1.10 36781    1
## phi                                63.71  89.29 54172    1
## r_Site_ID[CHATANOP,Intercept]      -0.52  -0.14 40136    1
## r_Site_ID[GENKAOP,Intercept]       -0.80  -0.38 39450    1
## r_Site_ID[GESASHIOP,Intercept]      0.89   1.35 45359    1
## r_Site_ID[HEIWAOP,Intercept]       -1.67  -1.28 41416    1
## r_Site_ID[HENTONAOP,Intercept]      1.02   1.56 48928    1
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.26   0.74 42361    1
## r_Site_ID[KEMINFR,Intercept]        0.38   0.86 44371    1
## r_Site_ID[KURASHIKIOP,Intercept]    0.97   1.43 45754    1
## r_Site_ID[MANABIFR,Intercept]       0.52   1.01 44389    1
## r_Site_ID[NAGOFR,Intercept]         1.05   1.52 46473    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]   0.68   1.12 43841    1
## r_Site_ID[OISTFR,Intercept]         0.35   0.82 43893    1
## r_Site_ID[OISTOP,Intercept]        -0.61  -0.18 41019    1
## r_Site_ID[OKUFR,Intercept]          0.07   0.53 43417    1
## r_Site_ID[OYAMAOP,Intercept]       -0.17   0.22 40450    1
## r_Site_ID[SEFAFR,Intercept]         0.95   1.41 46642    1
## r_Site_ID[SENBARUOP,Intercept]      0.04   0.44 40273    1
## r_Site_ID[SUEYOSHIFR,Intercept]     0.47   0.90 42185    1
## r_Site_ID[TAKEYANBARUF,Intercept]   0.28   0.76 43710    1
## r_Site_ID[TAMAGUSUKUFR,Intercept]   0.78   1.24 45281    1
## r_Site_ID[TOUNANOP,Intercept]       0.18   0.59 42028    1
## r_Site_ID[UEHARAFR,Intercept]      -0.26   0.14 40749    1
## r_Site_ID[YACHOOP,Intercept]       -0.41  -0.03 39848    1
## r_Site_ID[YONAFR,Intercept]         0.87   1.40 46216    1
## lprior                            -12.18 -11.59 50678    1
## lp__                               35.91  42.57 28506    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:22:32 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate  Est.Error      Q2.5     Q97.5
## R2 0.8644529 0.04139113 0.7596527 0.9174749
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.007368338
## 
## $expected
## [1] -0.0212766
## 
## $sd
## [1] 0.0411747
## 
## $p.value
## [1] 0.7355241
summary(mod_nonspatial_beta)
##  Family: beta 
##   Links: mu = logit; phi = identity 
## Formula: Stability ~ 1 + Landuse * Typhoon + (1 | Site_ID) 
##    Data: df (Number of observations: 48) 
##   Draws: 4 chains, each with iter = 50000; warmup = 5000; thin = 2;
##          total post-warmup draws = 90000
## 
## Group-Level Effects: 
## ~Site_ID (Number of levels: 24) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.77      0.14     0.55     1.10 1.00    36580    56347
## 
## Population-Level Effects: 
##                              Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## Intercept                        1.45      0.23     0.99     1.92 1.00    31176
## LanduseDeveloped                 0.37      0.36    -0.35     1.09 1.00    33282
## TyphoonPost                     -0.52      0.13    -0.78    -0.26 1.00    73958
## LanduseDeveloped:TyphoonPost     0.06      0.21    -0.36     0.48 1.00    73892
##                              Tail_ESS
## Intercept                       51479
## LanduseDeveloped                53671
## TyphoonPost                     77526
## LanduseDeveloped:TyphoonPost    78617
## 
## Family Specific Parameters: 
##     Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## phi    54.10     15.76    27.75    89.29 1.00    52795    68793
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

plot results:

mut_mod<-mod_nonspatial_beta %>%
  spread_draws(b_TyphoonPost, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_TyphoonPost + r_Site_ID) # get posterior distribution data for plotting
## Warning: `gather_()` was deprecated in tidyr 1.2.0.
## ℹ Please use `gather()` instead.
## ℹ The deprecated feature was likely used in the tidybayes package.
##   Please report the issue at <]8;;https://github.com/mjskay/tidybayes/issues/newhttps://github.com/mjskay/tidybayes/issues/new]8;;>.
# determine whether credible intervals span zero, and store as binary (to show in plot): 
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
}
rm(temp)
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor

# plot posterior typhoon effect
mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","skyblue")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (typhoon effect)",
       y = "Site") + 
  cowplot::theme_minimal_grid(font_size = 14,
                              colour = "grey92")

NDSI_Bio - no effect of typhoon or land use

# get pre vs post data for comparison
dat_pre<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Bio" & response_variable %in% 'Pre_mean') 
dat_post<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Bio" & response_variable %in% 'Post_mean')
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
#names(df)[1] <- names(Landuse_1000)[1]
#df <- left_join(df, Landuse_1000, by = "site_id")

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse * Typhoon + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 2 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()
## No divergences to plot.

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 

mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 516dc2723972b0b4959c45f1ed5792b7.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                     mean se_mean    sd   2.5%    25%    50%
## b_Intercept                        -0.12    0.00  0.14  -0.39  -0.21  -0.12
## b_LanduseDeveloped                  0.16    0.00  0.22  -0.26   0.02   0.16
## b_TyphoonPost                      -0.06    0.00  0.13  -0.31  -0.14  -0.06
## b_LanduseDeveloped:TyphoonPost     -0.02    0.00  0.20  -0.41  -0.15  -0.02
## sd_Site_ID__Intercept               0.38    0.00  0.10   0.21   0.32   0.38
## phi                                39.28    0.06 11.98  19.32  30.69  38.11
## r_Site_ID[CHATANOP,Intercept]      -0.20    0.00  0.22  -0.63  -0.34  -0.19
## r_Site_ID[GENKAOP,Intercept]       -0.18    0.00  0.23  -0.64  -0.33  -0.18
## r_Site_ID[GESASHIOP,Intercept]      0.16    0.00  0.22  -0.26   0.02   0.16
## r_Site_ID[HEIWAOP,Intercept]       -0.99    0.00  0.30  -1.57  -1.19  -1.00
## r_Site_ID[HENTONAOP,Intercept]      0.20    0.00  0.23  -0.24   0.05   0.20
## r_Site_ID[KATSUUDAKEFR,Intercept]  -0.03    0.00  0.22  -0.47  -0.17  -0.02
## r_Site_ID[KEMINFR,Intercept]        0.19    0.00  0.23  -0.26   0.03   0.18
## r_Site_ID[KURASHIKIOP,Intercept]    0.20    0.00  0.22  -0.23   0.05   0.19
## r_Site_ID[MANABIFR,Intercept]      -0.09    0.00  0.22  -0.54  -0.24  -0.09
## r_Site_ID[NAGOFR,Intercept]         0.38    0.00  0.23  -0.06   0.22   0.38
## r_Site_ID[NAKAGUSUKUFR,Intercept]   0.48    0.00  0.24   0.02   0.32   0.49
## r_Site_ID[OISTFR,Intercept]         0.00    0.00  0.22  -0.44  -0.15   0.00
## r_Site_ID[OISTOP,Intercept]        -0.31    0.00  0.23  -0.79  -0.47  -0.31
## r_Site_ID[OKUFR,Intercept]         -0.07    0.00  0.22  -0.52  -0.22  -0.07
## r_Site_ID[OYAMAOP,Intercept]       -0.17    0.00  0.22  -0.61  -0.32  -0.17
## r_Site_ID[SEFAFR,Intercept]         0.32    0.00  0.23  -0.11   0.17   0.32
## r_Site_ID[SENBARUOP,Intercept]     -0.11    0.00  0.22  -0.55  -0.25  -0.11
## r_Site_ID[SUEYOSHIFR,Intercept]    -0.03    0.00  0.22  -0.46  -0.17  -0.03
## r_Site_ID[TAKEYANBARUF,Intercept]   0.25    0.00  0.23  -0.19   0.10   0.25
## r_Site_ID[TAMAGUSUKUFR,Intercept]   0.28    0.00  0.22  -0.15   0.13   0.28
## r_Site_ID[TOUNANOP,Intercept]      -0.05    0.00  0.22  -0.48  -0.19  -0.05
## r_Site_ID[UEHARAFR,Intercept]       0.00    0.00  0.22  -0.43  -0.15   0.00
## r_Site_ID[YACHOOP,Intercept]       -0.27    0.00  0.22  -0.72  -0.42  -0.27
## r_Site_ID[YONAFR,Intercept]         0.05    0.00  0.22  -0.40  -0.10   0.05
## lprior                            -11.79    0.00  0.43 -12.62 -12.07 -11.79
## lp__                               11.11    0.04  6.89  -4.04   6.84  11.66
##                                      75%  97.5% n_eff Rhat
## b_Intercept                        -0.03   0.16 66365    1
## b_LanduseDeveloped                  0.31   0.59 67086    1
## b_TyphoonPost                       0.03   0.19 81927    1
## b_LanduseDeveloped:TyphoonPost      0.11   0.37 84023    1
## sd_Site_ID__Intercept               0.44   0.59 37528    1
## phi                                46.53  66.10 47388    1
## r_Site_ID[CHATANOP,Intercept]      -0.05   0.23 67034    1
## r_Site_ID[GENKAOP,Intercept]       -0.03   0.25 66753    1
## r_Site_ID[GESASHIOP,Intercept]      0.30   0.59 69049    1
## r_Site_ID[HEIWAOP,Intercept]       -0.80  -0.36 44594    1
## r_Site_ID[HENTONAOP,Intercept]      0.35   0.65 67669    1
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.12   0.41 69143    1
## r_Site_ID[KEMINFR,Intercept]        0.33   0.64 66051    1
## r_Site_ID[KURASHIKIOP,Intercept]    0.34   0.63 68340    1
## r_Site_ID[MANABIFR,Intercept]       0.06   0.34 69368    1
## r_Site_ID[NAGOFR,Intercept]         0.53   0.83 62249    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]   0.64   0.95 56803    1
## r_Site_ID[OISTFR,Intercept]         0.14   0.43 68255    1
## r_Site_ID[OISTOP,Intercept]        -0.16   0.13 63085    1
## r_Site_ID[OKUFR,Intercept]          0.07   0.36 68847    1
## r_Site_ID[OYAMAOP,Intercept]       -0.03   0.25 68638    1
## r_Site_ID[SEFAFR,Intercept]         0.47   0.77 63576    1
## r_Site_ID[SENBARUOP,Intercept]      0.03   0.31 70511    1
## r_Site_ID[SUEYOSHIFR,Intercept]     0.11   0.39 71330    1
## r_Site_ID[TAKEYANBARUF,Intercept]   0.40   0.71 63150    1
## r_Site_ID[TAMAGUSUKUFR,Intercept]   0.43   0.73 63898    1
## r_Site_ID[TOUNANOP,Intercept]       0.09   0.37 70160    1
## r_Site_ID[UEHARAFR,Intercept]       0.14   0.42 70037    1
## r_Site_ID[YACHOOP,Intercept]       -0.12   0.15 67128    1
## r_Site_ID[YONAFR,Intercept]         0.19   0.49 69208    1
## lprior                            -11.50 -10.92 43801    1
## lp__                               15.97  23.07 27026    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:24:08 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate Est.Error     Q2.5     Q97.5
## R2 0.5522608 0.1116597 0.270455 0.7092613
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.01638461
## 
## $expected
## [1] -0.0212766
## 
## $sd
## [1] 0.04114045
## 
## $p.value
## [1] 0.9053471
summary(mod_nonspatial_beta)
##  Family: beta 
##   Links: mu = logit; phi = identity 
## Formula: Stability ~ 1 + Landuse * Typhoon + (1 | Site_ID) 
##    Data: df (Number of observations: 48) 
##   Draws: 4 chains, each with iter = 50000; warmup = 5000; thin = 2;
##          total post-warmup draws = 90000
## 
## Group-Level Effects: 
## ~Site_ID (Number of levels: 24) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.38      0.10     0.21     0.59 1.00    38093    43725
## 
## Population-Level Effects: 
##                              Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## Intercept                       -0.12      0.14    -0.39     0.16 1.00    66450
## LanduseDeveloped                 0.16      0.22    -0.26     0.59 1.00    67120
## TyphoonPost                     -0.06      0.13    -0.31     0.19 1.00    81924
## LanduseDeveloped:TyphoonPost    -0.02      0.20    -0.41     0.37 1.00    84017
##                              Tail_ESS
## Intercept                       74207
## LanduseDeveloped                73786
## TyphoonPost                     80274
## LanduseDeveloped:TyphoonPost    79873
## 
## Family Specific Parameters: 
##     Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## phi    39.28     11.98    19.32    66.10 1.00    44675    50796
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

NDSI_Anthro - positive change after typhoon

# get pre vs post data for comparison
dat_pre<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Anth" & response_variable %in% 'Pre_mean') 
dat_post<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Anth" & response_variable %in% 'Post_mean')
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
#names(df)[1] <- names(Landuse_1000)[1]
#df <- left_join(df, Landuse_1000, by = "site_id")

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse * Typhoon + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 10 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()
## No divergences to plot.

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 516dc2723972b0b4959c45f1ed5792b7.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                     mean se_mean   sd   2.5%    25%    50%
## b_Intercept                        -0.51    0.00 0.26  -1.01  -0.67  -0.51
## b_LanduseDeveloped                 -0.44    0.00 0.40  -1.23  -0.70  -0.44
## b_TyphoonPost                       0.68    0.00 0.17   0.34   0.57   0.68
## b_LanduseDeveloped:TyphoonPost     -0.12    0.00 0.26  -0.62  -0.29  -0.12
## sd_Site_ID__Intercept               0.84    0.00 0.16   0.57   0.73   0.82
## phi                                26.25    0.03 7.78  13.27  20.69  25.46
## r_Site_ID[CHATANOP,Intercept]       0.80    0.00 0.36   0.11   0.57   0.80
## r_Site_ID[GENKAOP,Intercept]        0.99    0.00 0.38   0.25   0.74   0.99
## r_Site_ID[GESASHIOP,Intercept]     -0.83    0.00 0.36  -1.56  -1.06  -0.82
## r_Site_ID[HEIWAOP,Intercept]        2.07    0.00 0.43   1.25   1.78   2.06
## r_Site_ID[HENTONAOP,Intercept]     -0.77    0.00 0.41  -1.59  -1.03  -0.76
## r_Site_ID[KATSUUDAKEFR,Intercept]  -0.07    0.00 0.38  -0.83  -0.32  -0.07
## r_Site_ID[KEMINFR,Intercept]       -0.08    0.00 0.39  -0.86  -0.34  -0.08
## r_Site_ID[KURASHIKIOP,Intercept]   -0.91    0.00 0.37  -1.67  -1.15  -0.91
## r_Site_ID[MANABIFR,Intercept]      -0.28    0.00 0.39  -1.05  -0.53  -0.28
## r_Site_ID[NAGOFR,Intercept]        -0.84    0.00 0.37  -1.59  -1.09  -0.84
## r_Site_ID[NAKAGUSUKUFR,Intercept]  -0.44    0.00 0.36  -1.16  -0.67  -0.43
## r_Site_ID[OISTFR,Intercept]        -0.13    0.00 0.38  -0.90  -0.39  -0.13
## r_Site_ID[OISTOP,Intercept]         0.74    0.00 0.38  -0.01   0.48   0.74
## r_Site_ID[OKUFR,Intercept]          0.09    0.00 0.38  -0.68  -0.16   0.09
## r_Site_ID[OYAMAOP,Intercept]        0.34    0.00 0.35  -0.34   0.11   0.34
## r_Site_ID[SEFAFR,Intercept]        -0.76    0.00 0.37  -1.51  -1.00  -0.75
## r_Site_ID[SENBARUOP,Intercept]      0.17    0.00 0.35  -0.52  -0.06   0.17
## r_Site_ID[SUEYOSHIFR,Intercept]    -0.34    0.00 0.35  -1.04  -0.57  -0.33
## r_Site_ID[TAKEYANBARUF,Intercept]   0.07    0.00 0.39  -0.70  -0.18   0.07
## r_Site_ID[TAMAGUSUKUFR,Intercept]  -0.59    0.00 0.37  -1.34  -0.84  -0.59
## r_Site_ID[TOUNANOP,Intercept]      -0.09    0.00 0.35  -0.78  -0.32  -0.09
## r_Site_ID[UEHARAFR,Intercept]       0.86    0.00 0.36   0.15   0.62   0.86
## r_Site_ID[YACHOOP,Intercept]        0.52    0.00 0.35  -0.16   0.29   0.52
## r_Site_ID[YONAFR,Intercept]        -0.57    0.00 0.40  -1.38  -0.83  -0.56
## lprior                            -11.33    0.00 0.38 -12.06 -11.60 -11.34
## lp__                                6.76    0.04 6.58  -7.50   2.67   7.25
##                                      75%  97.5% n_eff Rhat
## b_Intercept                        -0.34   0.00 35142    1
## b_LanduseDeveloped                 -0.18   0.34 37730    1
## b_TyphoonPost                       0.79   1.00 75705    1
## b_LanduseDeveloped:TyphoonPost      0.05   0.40 77840    1
## sd_Site_ID__Intercept               0.93   1.21 36870    1
## phi                                30.98  43.58 51778    1
## r_Site_ID[CHATANOP,Intercept]       1.04   1.51 46221    1
## r_Site_ID[GENKAOP,Intercept]        1.24   1.76 47218    1
## r_Site_ID[GESASHIOP,Intercept]     -0.58  -0.12 48761    1
## r_Site_ID[HEIWAOP,Intercept]        2.34   2.94 50357    1
## r_Site_ID[HENTONAOP,Intercept]     -0.49   0.01 49059    1
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.19   0.68 47566    1
## r_Site_ID[KEMINFR,Intercept]        0.18   0.68 47843    1
## r_Site_ID[KURASHIKIOP,Intercept]   -0.66  -0.19 48066    1
## r_Site_ID[MANABIFR,Intercept]      -0.02   0.47 47519    1
## r_Site_ID[NAGOFR,Intercept]        -0.60  -0.12 48531    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]  -0.20   0.27 48851    1
## r_Site_ID[OISTFR,Intercept]         0.12   0.61 46565    1
## r_Site_ID[OISTOP,Intercept]         0.99   1.49 46543    1
## r_Site_ID[OKUFR,Intercept]          0.34   0.83 47021    1
## r_Site_ID[OYAMAOP,Intercept]        0.57   1.04 47050    1
## r_Site_ID[SEFAFR,Intercept]        -0.51  -0.04 49403    1
## r_Site_ID[SENBARUOP,Intercept]      0.40   0.85 46123    1
## r_Site_ID[SUEYOSHIFR,Intercept]    -0.10   0.35 46931    1
## r_Site_ID[TAKEYANBARUF,Intercept]   0.33   0.82 47210    1
## r_Site_ID[TAMAGUSUKUFR,Intercept]  -0.35   0.12 48776    1
## r_Site_ID[TOUNANOP,Intercept]       0.15   0.60 46369    1
## r_Site_ID[UEHARAFR,Intercept]       1.10   1.60 48542    1
## r_Site_ID[YACHOOP,Intercept]        0.75   1.21 44575    1
## r_Site_ID[YONAFR,Intercept]        -0.30   0.20 48047    1
## lprior                            -11.08 -10.56 46936    1
## lp__                               11.39  18.14 28032    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:25:36 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##    Estimate Est.Error      Q2.5     Q97.5
## R2 0.807011 0.0520729 0.6761066 0.8764128
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.006962
## 
## $expected
## [1] -0.0212766
## 
## $sd
## [1] 0.04120184
## 
## $p.value
## [1] 0.7282712

Plot typhoon effect:

mut_mod<-mod_nonspatial_beta %>%
  spread_draws(b_TyphoonPost, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_TyphoonPost + r_Site_ID) # get posterior distribution data for plotting

# determine whether credible intervals span zero, and store as binary (to show in plot): 
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
}
rm(temp)
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor

# plot posterior typhoon effect
mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","skyblue")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (typhoon effect)",
       y = "Site") + 
  cowplot::theme_minimal_grid(font_size = 14,
                              colour = "grey92")

acoustic index temporal variability

NDSI - no effect of typhoon or land use

# get pre vs post data for comparison
dat_pre<-tidy.stability_AI %>%
  filter(Index %in% "NDSI" & response_variable %in% 'Pre_Var') 
dat_post<-tidy.stability_AI %>%
  filter(Index %in% "NDSI" & response_variable %in% 'Post_Var')
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
#names(df)[1] <- names(Landuse_1000)[1]
#df <- left_join(df, Landuse_1000, by = "site_id")

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

# fit random intercept and slope model because random slope model didn't converge well.
mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse * Typhoon + (1+Landuse*Typhoon|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Trying to compile a simple C file
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
## Start sampling
## Warning: There were 566 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 35 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 1b3a3d37e3bf884746f549577180da75.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                                               mean se_mean
## b_Intercept                                                  -0.16    0.00
## b_LanduseDeveloped                                            0.36    0.00
## b_TyphoonPost                                                -0.10    0.00
## b_LanduseDeveloped:TyphoonPost                               -0.22    0.00
## sd_Site_ID__Intercept                                         1.24    0.00
## sd_Site_ID__LanduseDeveloped                                  0.84    0.01
## sd_Site_ID__TyphoonPost                                       0.98    0.01
## sd_Site_ID__LanduseDeveloped:TyphoonPost                      1.48    0.00
## cor_Site_ID__Intercept__LanduseDeveloped                     -0.40    0.00
## cor_Site_ID__Intercept__TyphoonPost                          -0.31    0.00
## cor_Site_ID__LanduseDeveloped__TyphoonPost                    0.20    0.00
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost          0.16    0.00
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost   0.04    0.00
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost       -0.05    0.00
## phi                                                          11.42    0.18
## r_Site_ID[CHATANOP,Intercept]                                -0.15    0.00
## r_Site_ID[GENKAOP,Intercept]                                 -0.16    0.01
## r_Site_ID[GESASHIOP,Intercept]                                0.84    0.01
## r_Site_ID[HEIWAOP,Intercept]                                 -3.77    0.01
## r_Site_ID[HENTONAOP,Intercept]                                0.56    0.01
## r_Site_ID[KATSUUDAKEFR,Intercept]                            -0.16    0.01
## r_Site_ID[KEMINFR,Intercept]                                 -0.34    0.01
## r_Site_ID[KURASHIKIOP,Intercept]                              0.78    0.00
## r_Site_ID[MANABIFR,Intercept]                                 0.35    0.01
## r_Site_ID[NAGOFR,Intercept]                                   0.78    0.00
## r_Site_ID[NAKAGUSUKUFR,Intercept]                             0.03    0.00
## r_Site_ID[OISTFR,Intercept]                                   0.05    0.00
## r_Site_ID[OISTOP,Intercept]                                  -0.57    0.02
## r_Site_ID[OKUFR,Intercept]                                   -0.33    0.01
## r_Site_ID[OYAMAOP,Intercept]                                  0.05    0.01
## r_Site_ID[SEFAFR,Intercept]                                   0.31    0.00
## r_Site_ID[SENBARUOP,Intercept]                                0.55    0.00
## r_Site_ID[SUEYOSHIFR,Intercept]                               0.89    0.00
## r_Site_ID[TAKEYANBARUF,Intercept]                             0.26    0.01
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            -0.15    0.00
## r_Site_ID[TOUNANOP,Intercept]                                 0.40    0.01
## r_Site_ID[UEHARAFR,Intercept]                                -0.36    0.00
## r_Site_ID[YACHOOP,Intercept]                                 -0.22    0.00
## r_Site_ID[YONAFR,Intercept]                                   0.30    0.01
## r_Site_ID[CHATANOP,LanduseDeveloped]                          0.01    0.01
## r_Site_ID[GENKAOP,LanduseDeveloped]                           0.19    0.01
## r_Site_ID[GESASHIOP,LanduseDeveloped]                        -0.36    0.01
## r_Site_ID[HEIWAOP,LanduseDeveloped]                           1.37    0.01
## r_Site_ID[HENTONAOP,LanduseDeveloped]                         0.24    0.01
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                     -0.04    0.01
## r_Site_ID[KEMINFR,LanduseDeveloped]                           0.00    0.01
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                      -0.27    0.01
## r_Site_ID[MANABIFR,LanduseDeveloped]                          0.11    0.01
## r_Site_ID[NAGOFR,LanduseDeveloped]                           -0.25    0.00
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                      0.03    0.00
## r_Site_ID[OISTFR,LanduseDeveloped]                           -0.06    0.00
## r_Site_ID[OISTOP,LanduseDeveloped]                           -0.62    0.02
## r_Site_ID[OKUFR,LanduseDeveloped]                            -0.18    0.01
## r_Site_ID[OYAMAOP,LanduseDeveloped]                          -0.14    0.01
## r_Site_ID[SEFAFR,LanduseDeveloped]                           -0.06    0.00
## r_Site_ID[SENBARUOP,LanduseDeveloped]                        -0.21    0.01
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                       -0.33    0.00
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      0.23    0.00
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                      0.14    0.01
## r_Site_ID[TOUNANOP,LanduseDeveloped]                         -0.24    0.01
## r_Site_ID[UEHARAFR,LanduseDeveloped]                          0.19    0.00
## r_Site_ID[YACHOOP,LanduseDeveloped]                           0.11    0.00
## r_Site_ID[YONAFR,LanduseDeveloped]                            0.14    0.00
## r_Site_ID[CHATANOP,TyphoonPost]                              -0.41    0.00
## r_Site_ID[GENKAOP,TyphoonPost]                                0.61    0.01
## r_Site_ID[GESASHIOP,TyphoonPost]                             -0.79    0.01
## r_Site_ID[HEIWAOP,TyphoonPost]                                0.94    0.01
## r_Site_ID[HENTONAOP,TyphoonPost]                              0.02    0.00
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                           0.08    0.01
## r_Site_ID[KEMINFR,TyphoonPost]                                0.29    0.01
## r_Site_ID[KURASHIKIOP,TyphoonPost]                            0.01    0.00
## r_Site_ID[MANABIFR,TyphoonPost]                              -0.12    0.00
## r_Site_ID[NAGOFR,TyphoonPost]                                 0.16    0.00
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                           0.36    0.00
## r_Site_ID[OISTFR,TyphoonPost]                                -0.20    0.00
## r_Site_ID[OISTOP,TyphoonPost]                                -0.95    0.01
## r_Site_ID[OKUFR,TyphoonPost]                                 -0.13    0.00
## r_Site_ID[OYAMAOP,TyphoonPost]                               -1.16    0.01
## r_Site_ID[SEFAFR,TyphoonPost]                                 0.43    0.00
## r_Site_ID[SENBARUOP,TyphoonPost]                             -0.17    0.00
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                            -0.27    0.00
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                           0.31    0.01
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                           0.94    0.01
## r_Site_ID[TOUNANOP,TyphoonPost]                              -1.02    0.01
## r_Site_ID[UEHARAFR,TyphoonPost]                               0.63    0.00
## r_Site_ID[YACHOOP,TyphoonPost]                                0.34    0.00
## r_Site_ID[YONAFR,TyphoonPost]                                 0.07    0.00
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]              0.01    0.01
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]               1.12    0.01
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]             0.25    0.01
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]              -0.87    0.01
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]             0.46    0.00
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]          0.03    0.01
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]               0.33    0.00
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]           0.15    0.01
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              0.04    0.00
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                0.14    0.01
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]         -0.03    0.01
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]               -0.37    0.00
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               -2.32    0.01
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                -0.51    0.00
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]               0.12    0.01
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                0.01    0.01
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]             0.12    0.01
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]            0.21    0.01
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]          0.84    0.01
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]         -0.12    0.01
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]              0.18    0.01
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]             -0.12    0.01
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]              -0.07    0.01
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                0.36    0.00
## lprior                                                      -17.86    0.02
## lp__                                                        -97.71    0.24
##                                                                sd    2.5%
## b_Intercept                                                  0.39   -0.93
## b_LanduseDeveloped                                           0.59   -0.80
## b_TyphoonPost                                                0.40   -0.91
## b_LanduseDeveloped:TyphoonPost                               0.80   -1.82
## sd_Site_ID__Intercept                                        0.31    0.75
## sd_Site_ID__LanduseDeveloped                                 0.60    0.04
## sd_Site_ID__TyphoonPost                                      0.50    0.07
## sd_Site_ID__LanduseDeveloped:TyphoonPost                     0.85    0.11
## cor_Site_ID__Intercept__LanduseDeveloped                     0.43   -0.95
## cor_Site_ID__Intercept__TyphoonPost                          0.34   -0.82
## cor_Site_ID__LanduseDeveloped__TyphoonPost                   0.43   -0.70
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost         0.43   -0.72
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost  0.44   -0.79
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost       0.44   -0.82
## phi                                                          8.26    3.87
## r_Site_ID[CHATANOP,Intercept]                                0.63   -1.41
## r_Site_ID[GENKAOP,Intercept]                                 1.06   -2.50
## r_Site_ID[GESASHIOP,Intercept]                               0.69   -0.48
## r_Site_ID[HEIWAOP,Intercept]                                 0.92   -5.72
## r_Site_ID[HENTONAOP,Intercept]                               1.03   -1.67
## r_Site_ID[KATSUUDAKEFR,Intercept]                            0.94   -2.02
## r_Site_ID[KEMINFR,Intercept]                                 0.96   -2.30
## r_Site_ID[KURASHIKIOP,Intercept]                             0.64   -0.44
## r_Site_ID[MANABIFR,Intercept]                                0.95   -1.62
## r_Site_ID[NAGOFR,Intercept]                                  0.64   -0.45
## r_Site_ID[NAKAGUSUKUFR,Intercept]                            0.63   -1.22
## r_Site_ID[OISTFR,Intercept]                                  0.93   -1.76
## r_Site_ID[OISTOP,Intercept]                                  1.45   -3.04
## r_Site_ID[OKUFR,Intercept]                                   0.98   -2.19
## r_Site_ID[OYAMAOP,Intercept]                                 0.70   -1.34
## r_Site_ID[SEFAFR,Intercept]                                  0.63   -0.92
## r_Site_ID[SENBARUOP,Intercept]                               0.63   -0.69
## r_Site_ID[SUEYOSHIFR,Intercept]                              0.65   -0.36
## r_Site_ID[TAKEYANBARUF,Intercept]                            1.00   -1.90
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            0.67   -1.48
## r_Site_ID[TOUNANOP,Intercept]                                0.69   -0.94
## r_Site_ID[UEHARAFR,Intercept]                                0.66   -1.67
## r_Site_ID[YACHOOP,Intercept]                                 0.63   -1.48
## r_Site_ID[YONAFR,Intercept]                                  0.95   -1.68
## r_Site_ID[CHATANOP,LanduseDeveloped]                         0.81   -1.72
## r_Site_ID[GENKAOP,LanduseDeveloped]                          0.93   -1.64
## r_Site_ID[GESASHIOP,LanduseDeveloped]                        0.91   -2.57
## r_Site_ID[HEIWAOP,LanduseDeveloped]                          1.84   -1.20
## r_Site_ID[HENTONAOP,LanduseDeveloped]                        0.92   -1.40
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                     0.81   -1.92
## r_Site_ID[KEMINFR,LanduseDeveloped]                          0.84   -1.87
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                      0.85   -2.26
## r_Site_ID[MANABIFR,LanduseDeveloped]                         0.84   -1.56
## r_Site_ID[NAGOFR,LanduseDeveloped]                           0.85   -2.26
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                     0.79   -1.66
## r_Site_ID[OISTFR,LanduseDeveloped]                           0.80   -1.86
## r_Site_ID[OISTOP,LanduseDeveloped]                           1.35   -4.03
## r_Site_ID[OKUFR,LanduseDeveloped]                            0.86   -2.30
## r_Site_ID[OYAMAOP,LanduseDeveloped]                          0.92   -2.21
## r_Site_ID[SEFAFR,LanduseDeveloped]                           0.81   -1.86
## r_Site_ID[SENBARUOP,LanduseDeveloped]                        0.82   -2.14
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                       0.86   -2.42
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                     0.89   -1.41
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                     0.89   -1.65
## r_Site_ID[TOUNANOP,LanduseDeveloped]                         0.91   -2.39
## r_Site_ID[UEHARAFR,LanduseDeveloped]                         0.84   -1.44
## r_Site_ID[YACHOOP,LanduseDeveloped]                          0.79   -1.49
## r_Site_ID[YONAFR,LanduseDeveloped]                           0.83   -1.48
## r_Site_ID[CHATANOP,TyphoonPost]                              0.71   -1.94
## r_Site_ID[GENKAOP,TyphoonPost]                               1.05   -1.26
## r_Site_ID[GESASHIOP,TyphoonPost]                             0.82   -2.56
## r_Site_ID[HEIWAOP,TyphoonPost]                               1.05   -0.96
## r_Site_ID[HENTONAOP,TyphoonPost]                             0.87   -1.83
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                          0.81   -1.59
## r_Site_ID[KEMINFR,TyphoonPost]                               0.86   -1.35
## r_Site_ID[KURASHIKIOP,TyphoonPost]                           0.67   -1.36
## r_Site_ID[MANABIFR,TyphoonPost]                              0.83   -1.95
## r_Site_ID[NAGOFR,TyphoonPost]                                0.68   -1.18
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                          0.69   -0.93
## r_Site_ID[OISTFR,TyphoonPost]                                0.82   -1.98
## r_Site_ID[OISTOP,TyphoonPost]                                1.49   -4.25
## r_Site_ID[OKUFR,TyphoonPost]                                 0.86   -1.95
## r_Site_ID[OYAMAOP,TyphoonPost]                               0.99   -3.24
## r_Site_ID[SEFAFR,TyphoonPost]                                0.72   -0.85
## r_Site_ID[SENBARUOP,TyphoonPost]                             0.66   -1.57
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                            0.68   -1.72
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                          0.92   -1.51
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                          0.88   -0.43
## r_Site_ID[TOUNANOP,TyphoonPost]                              0.92   -2.96
## r_Site_ID[UEHARAFR,TyphoonPost]                              0.77   -0.65
## r_Site_ID[YACHOOP,TyphoonPost]                               0.69   -0.95
## r_Site_ID[YONAFR,TyphoonPost]                                0.82   -1.65
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]             1.52   -3.10
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]              1.21   -0.75
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]            1.65   -2.99
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]              2.85   -7.18
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]            1.07   -1.56
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]         0.99   -2.04
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]              1.02   -1.62
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]          1.58   -3.19
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]             1.00   -2.07
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]               1.59   -3.26
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]         1.52   -3.39
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]               1.01   -2.67
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               1.70   -6.02
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                1.05   -2.89
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]              1.78   -3.31
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]               1.55   -3.43
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]            1.53   -3.03
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]           1.59   -3.08
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]         1.12   -1.05
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]         1.68   -3.93
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]             1.70   -3.07
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]             1.57   -3.65
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]              1.51   -3.37
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]               1.01   -1.60
## lprior                                                       1.21  -20.66
## lp__                                                        15.67 -124.95
##                                                                 25%    50%
## b_Intercept                                                   -0.41  -0.16
## b_LanduseDeveloped                                            -0.02   0.36
## b_TyphoonPost                                                 -0.36  -0.10
## b_LanduseDeveloped:TyphoonPost                                -0.74  -0.23
## sd_Site_ID__Intercept                                          1.03   1.21
## sd_Site_ID__LanduseDeveloped                                   0.36   0.74
## sd_Site_ID__TyphoonPost                                        0.61   0.98
## sd_Site_ID__LanduseDeveloped:TyphoonPost                       0.87   1.41
## cor_Site_ID__Intercept__LanduseDeveloped                      -0.76  -0.51
## cor_Site_ID__Intercept__TyphoonPost                           -0.56  -0.36
## cor_Site_ID__LanduseDeveloped__TyphoonPost                    -0.10   0.26
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost          -0.16   0.19
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost   -0.30   0.05
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost        -0.39  -0.06
## phi                                                            6.34   8.83
## r_Site_ID[CHATANOP,Intercept]                                 -0.55  -0.14
## r_Site_ID[GENKAOP,Intercept]                                  -0.77  -0.10
## r_Site_ID[GESASHIOP,Intercept]                                 0.37   0.83
## r_Site_ID[HEIWAOP,Intercept]                                  -4.36  -3.71
## r_Site_ID[HENTONAOP,Intercept]                                -0.02   0.60
## r_Site_ID[KATSUUDAKEFR,Intercept]                             -0.73  -0.16
## r_Site_ID[KEMINFR,Intercept]                                  -0.91  -0.33
## r_Site_ID[KURASHIKIOP,Intercept]                               0.36   0.77
## r_Site_ID[MANABIFR,Intercept]                                 -0.22   0.36
## r_Site_ID[NAGOFR,Intercept]                                    0.36   0.77
## r_Site_ID[NAKAGUSUKUFR,Intercept]                             -0.38   0.02
## r_Site_ID[OISTFR,Intercept]                                   -0.51   0.04
## r_Site_ID[OISTOP,Intercept]                                   -1.50  -0.74
## r_Site_ID[OKUFR,Intercept]                                    -0.94  -0.37
## r_Site_ID[OYAMAOP,Intercept]                                  -0.40   0.07
## r_Site_ID[SEFAFR,Intercept]                                   -0.10   0.30
## r_Site_ID[SENBARUOP,Intercept]                                 0.13   0.54
## r_Site_ID[SUEYOSHIFR,Intercept]                                0.45   0.88
## r_Site_ID[TAKEYANBARUF,Intercept]                             -0.32   0.31
## r_Site_ID[TAMAGUSUKUFR,Intercept]                             -0.60  -0.15
## r_Site_ID[TOUNANOP,Intercept]                                 -0.06   0.40
## r_Site_ID[UEHARAFR,Intercept]                                 -0.78  -0.35
## r_Site_ID[YACHOOP,Intercept]                                  -0.62  -0.21
## r_Site_ID[YONAFR,Intercept]                                   -0.26   0.32
## r_Site_ID[CHATANOP,LanduseDeveloped]                          -0.32   0.00
## r_Site_ID[GENKAOP,LanduseDeveloped]                           -0.23   0.07
## r_Site_ID[GESASHIOP,LanduseDeveloped]                         -0.76  -0.17
## r_Site_ID[HEIWAOP,LanduseDeveloped]                            0.05   0.89
## r_Site_ID[HENTONAOP,LanduseDeveloped]                         -0.20   0.07
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                      -0.37  -0.01
## r_Site_ID[KEMINFR,LanduseDeveloped]                           -0.34   0.00
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                       -0.63  -0.12
## r_Site_ID[MANABIFR,LanduseDeveloped]                          -0.26   0.02
## r_Site_ID[NAGOFR,LanduseDeveloped]                            -0.61  -0.11
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                      -0.30   0.01
## r_Site_ID[OISTFR,LanduseDeveloped]                            -0.39  -0.02
## r_Site_ID[OISTOP,LanduseDeveloped]                            -1.21  -0.27
## r_Site_ID[OKUFR,LanduseDeveloped]                             -0.51  -0.05
## r_Site_ID[OYAMAOP,LanduseDeveloped]                           -0.52  -0.04
## r_Site_ID[SEFAFR,LanduseDeveloped]                            -0.39  -0.02
## r_Site_ID[SENBARUOP,LanduseDeveloped]                         -0.55  -0.08
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                        -0.71  -0.15
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      -0.19   0.08
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                      -0.24   0.05
## r_Site_ID[TOUNANOP,LanduseDeveloped]                          -0.61  -0.09
## r_Site_ID[UEHARAFR,LanduseDeveloped]                          -0.19   0.07
## r_Site_ID[YACHOOP,LanduseDeveloped]                           -0.23   0.04
## r_Site_ID[YONAFR,LanduseDeveloped]                            -0.23   0.04
## r_Site_ID[CHATANOP,TyphoonPost]                               -0.84  -0.31
## r_Site_ID[GENKAOP,TyphoonPost]                                -0.04   0.44
## r_Site_ID[GESASHIOP,TyphoonPost]                              -1.35  -0.70
## r_Site_ID[HEIWAOP,TyphoonPost]                                 0.16   0.87
## r_Site_ID[HENTONAOP,TyphoonPost]                              -0.43   0.01
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                           -0.34   0.04
## r_Site_ID[KEMINFR,TyphoonPost]                                -0.17   0.18
## r_Site_ID[KURASHIKIOP,TyphoonPost]                            -0.38   0.00
## r_Site_ID[MANABIFR,TyphoonPost]                               -0.54  -0.06
## r_Site_ID[NAGOFR,TyphoonPost]                                 -0.24   0.10
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                           -0.07   0.27
## r_Site_ID[OISTFR,TyphoonPost]                                 -0.65  -0.12
## r_Site_ID[OISTOP,TyphoonPost]                                 -1.88  -0.69
## r_Site_ID[OKUFR,TyphoonPost]                                  -0.58  -0.07
## r_Site_ID[OYAMAOP,TyphoonPost]                                -1.86  -1.07
## r_Site_ID[SEFAFR,TyphoonPost]                                 -0.03   0.34
## r_Site_ID[SENBARUOP,TyphoonPost]                              -0.55  -0.11
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                             -0.68  -0.20
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                           -0.20   0.20
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                            0.20   0.85
## r_Site_ID[TOUNANOP,TyphoonPost]                               -1.66  -0.93
## r_Site_ID[UEHARAFR,TyphoonPost]                                0.05   0.53
## r_Site_ID[YACHOOP,TyphoonPost]                                -0.08   0.26
## r_Site_ID[YONAFR,TyphoonPost]                                 -0.36   0.04
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]              -0.72  -0.02
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]                0.24   0.95
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]             -0.57   0.09
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]               -2.34  -0.55
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]             -0.14   0.34
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]          -0.49   0.01
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]               -0.24   0.21
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]           -0.58   0.09
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              -0.48   0.03
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                -0.60   0.09
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]          -0.72   0.01
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]                -0.90  -0.25
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]                -3.40  -2.20
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                 -1.08  -0.38
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]               -0.78   0.00
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                -0.68   0.03
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]             -0.60   0.06
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]            -0.54   0.11
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]           0.07   0.68
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]          -0.84   0.00
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]              -0.67   0.03
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]              -0.83  -0.03
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]               -0.76  -0.02
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                -0.19   0.26
## lprior                                                       -18.57 -17.67
## lp__                                                        -108.76 -99.09
##                                                                75%  97.5% n_eff
## b_Intercept                                                   0.10   0.62 12861
## b_LanduseDeveloped                                            0.75   1.53 53362
## b_TyphoonPost                                                 0.16   0.69 32442
## b_LanduseDeveloped:TyphoonPost                                0.29   1.38 43285
## sd_Site_ID__Intercept                                         1.42   1.94  4289
## sd_Site_ID__LanduseDeveloped                                  1.22   2.23  8835
## sd_Site_ID__TyphoonPost                                       1.32   1.97  6456
## sd_Site_ID__LanduseDeveloped:TyphoonPost                      2.00   3.37 32776
## cor_Site_ID__Intercept__LanduseDeveloped                     -0.13   0.62 35193
## cor_Site_ID__Intercept__TyphoonPost                          -0.11   0.49 48553
## cor_Site_ID__LanduseDeveloped__TyphoonPost                    0.55   0.87 34255
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost          0.50   0.87 38891
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost   0.38   0.82 48473
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost        0.29   0.78 53036
## phi                                                          13.46  34.80  2100
## r_Site_ID[CHATANOP,Intercept]                                 0.26   1.08 26017
## r_Site_ID[GENKAOP,Intercept]                                  0.52   1.83  7556
## r_Site_ID[GESASHIOP,Intercept]                                1.29   2.23 16121
## r_Site_ID[HEIWAOP,Intercept]                                 -3.11  -2.13 11073
## r_Site_ID[HENTONAOP,Intercept]                                1.20   2.52  9148
## r_Site_ID[KATSUUDAKEFR,Intercept]                             0.39   1.76 10281
## r_Site_ID[KEMINFR,Intercept]                                  0.25   1.59 21222
## r_Site_ID[KURASHIKIOP,Intercept]                              1.19   2.09 20777
## r_Site_ID[MANABIFR,Intercept]                                 0.93   2.26 26248
## r_Site_ID[NAGOFR,Intercept]                                   1.19   2.08 33055
## r_Site_ID[NAKAGUSUKUFR,Intercept]                             0.43   1.28 30445
## r_Site_ID[OISTFR,Intercept]                                   0.61   1.98 37816
## r_Site_ID[OISTOP,Intercept]                                   0.19   2.82  5421
## r_Site_ID[OKUFR,Intercept]                                    0.23   1.76 12033
## r_Site_ID[OYAMAOP,Intercept]                                  0.52   1.40 18103
## r_Site_ID[SEFAFR,Intercept]                                   0.71   1.59 34715
## r_Site_ID[SENBARUOP,Intercept]                                0.95   1.83 16810
## r_Site_ID[SUEYOSHIFR,Intercept]                               1.31   2.20 22636
## r_Site_ID[TAKEYANBARUF,Intercept]                             0.89   2.15 36589
## r_Site_ID[TAMAGUSUKUFR,Intercept]                             0.30   1.18 32927
## r_Site_ID[TOUNANOP,Intercept]                                 0.85   1.75 13779
## r_Site_ID[UEHARAFR,Intercept]                                 0.08   0.92 44021
## r_Site_ID[YACHOOP,Intercept]                                  0.20   1.02 36736
## r_Site_ID[YONAFR,Intercept]                                   0.88   2.15 31695
## r_Site_ID[CHATANOP,LanduseDeveloped]                          0.34   1.72  9841
## r_Site_ID[GENKAOP,LanduseDeveloped]                           0.59   2.43  7086
## r_Site_ID[GESASHIOP,LanduseDeveloped]                         0.10   1.23 32061
## r_Site_ID[HEIWAOP,LanduseDeveloped]                           2.39   5.80 15355
## r_Site_ID[HENTONAOP,LanduseDeveloped]                         0.59   2.54  5480
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                      0.31   1.64  7431
## r_Site_ID[KEMINFR,LanduseDeveloped]                           0.35   1.80 13956
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                       0.13   1.31 18217
## r_Site_ID[MANABIFR,LanduseDeveloped]                          0.43   2.11 14646
## r_Site_ID[NAGOFR,LanduseDeveloped]                            0.14   1.34 43687
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                      0.36   1.73 40525
## r_Site_ID[OISTFR,LanduseDeveloped]                            0.28   1.63 43012
## r_Site_ID[OISTOP,LanduseDeveloped]                            0.13   1.55  5824
## r_Site_ID[OKUFR,LanduseDeveloped]                             0.21   1.45 10627
## r_Site_ID[OYAMAOP,LanduseDeveloped]                           0.27   1.69 29461
## r_Site_ID[SEFAFR,LanduseDeveloped]                            0.29   1.63 38704
## r_Site_ID[SENBARUOP,LanduseDeveloped]                         0.16   1.34 12261
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                        0.10   1.21 41514
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      0.60   2.39 32582
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                      0.51   2.18 11728
## r_Site_ID[TOUNANOP,LanduseDeveloped]                          0.18   1.45 12899
## r_Site_ID[UEHARAFR,LanduseDeveloped]                          0.53   2.12 32144
## r_Site_ID[YACHOOP,LanduseDeveloped]                           0.43   1.92 37233
## r_Site_ID[YONAFR,LanduseDeveloped]                            0.46   2.11 36780
## r_Site_ID[CHATANOP,TyphoonPost]                               0.05   0.87 33622
## r_Site_ID[GENKAOP,TyphoonPost]                                1.23   2.94 17802
## r_Site_ID[GESASHIOP,TyphoonPost]                             -0.14   0.53 18177
## r_Site_ID[HEIWAOP,TyphoonPost]                                1.66   3.09 24222
## r_Site_ID[HENTONAOP,TyphoonPost]                              0.49   1.82 46330
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                           0.50   1.80 20197
## r_Site_ID[KEMINFR,TyphoonPost]                                0.76   2.16 27451
## r_Site_ID[KURASHIKIOP,TyphoonPost]                            0.39   1.41 49377
## r_Site_ID[MANABIFR,TyphoonPost]                               0.32   1.54 36066
## r_Site_ID[NAGOFR,TyphoonPost]                                 0.56   1.62 53703
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                           0.78   1.84 40936
## r_Site_ID[OISTFR,TyphoonPost]                                 0.24   1.43 34497
## r_Site_ID[OISTOP,TyphoonPost]                                 0.04   1.64 12401
## r_Site_ID[OKUFR,TyphoonPost]                                  0.32   1.61 42482
## r_Site_ID[OYAMAOP,TyphoonPost]                               -0.32   0.32 11062
## r_Site_ID[SEFAFR,TyphoonPost]                                 0.88   2.00 36300
## r_Site_ID[SENBARUOP,TyphoonPost]                              0.21   1.15 36145
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                             0.14   1.04 40193
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                           0.84   2.30 23073
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                           1.55   2.81 21887
## r_Site_ID[TOUNANOP,TyphoonPost]                              -0.25   0.38 12083
## r_Site_ID[UEHARAFR,TyphoonPost]                               1.13   2.29 30824
## r_Site_ID[YACHOOP,TyphoonPost]                                0.75   1.83 40887
## r_Site_ID[YONAFR,TyphoonPost]                                 0.51   1.80 48586
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]              0.70   3.34 52212
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]               1.82   3.93 41462
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]             1.00   4.05 52845
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]               0.61   4.66 40189
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]             1.04   2.83 53075
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]          0.54   2.12 34538
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]               0.87   2.61 45398
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]           0.90   3.53 24164
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              0.58   2.15 50574
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                0.89   3.51 47380
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]          0.70   3.05 50238
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]                0.20   1.53 49965
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               -1.03   0.31 29953
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                 0.09   1.43 48796
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]               0.88   4.25 34376
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                0.77   3.17 58956
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]             0.83   3.46 56052
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]            0.97   3.67 44075
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]          1.47   3.42 40521
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]          0.71   3.15 32201
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]              0.92   4.11 47145
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]              0.64   2.98 54907
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]               0.64   3.06 44274
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                0.90   2.61 60570
## lprior                                                      -16.96 -16.04  4873
## lp__                                                        -87.95 -63.28  4244
##                                                             Rhat
## b_Intercept                                                    1
## b_LanduseDeveloped                                             1
## b_TyphoonPost                                                  1
## b_LanduseDeveloped:TyphoonPost                                 1
## sd_Site_ID__Intercept                                          1
## sd_Site_ID__LanduseDeveloped                                   1
## sd_Site_ID__TyphoonPost                                        1
## sd_Site_ID__LanduseDeveloped:TyphoonPost                       1
## cor_Site_ID__Intercept__LanduseDeveloped                       1
## cor_Site_ID__Intercept__TyphoonPost                            1
## cor_Site_ID__LanduseDeveloped__TyphoonPost                     1
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost           1
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost    1
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost         1
## phi                                                            1
## r_Site_ID[CHATANOP,Intercept]                                  1
## r_Site_ID[GENKAOP,Intercept]                                   1
## r_Site_ID[GESASHIOP,Intercept]                                 1
## r_Site_ID[HEIWAOP,Intercept]                                   1
## r_Site_ID[HENTONAOP,Intercept]                                 1
## r_Site_ID[KATSUUDAKEFR,Intercept]                              1
## r_Site_ID[KEMINFR,Intercept]                                   1
## r_Site_ID[KURASHIKIOP,Intercept]                               1
## r_Site_ID[MANABIFR,Intercept]                                  1
## r_Site_ID[NAGOFR,Intercept]                                    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]                              1
## r_Site_ID[OISTFR,Intercept]                                    1
## r_Site_ID[OISTOP,Intercept]                                    1
## r_Site_ID[OKUFR,Intercept]                                     1
## r_Site_ID[OYAMAOP,Intercept]                                   1
## r_Site_ID[SEFAFR,Intercept]                                    1
## r_Site_ID[SENBARUOP,Intercept]                                 1
## r_Site_ID[SUEYOSHIFR,Intercept]                                1
## r_Site_ID[TAKEYANBARUF,Intercept]                              1
## r_Site_ID[TAMAGUSUKUFR,Intercept]                              1
## r_Site_ID[TOUNANOP,Intercept]                                  1
## r_Site_ID[UEHARAFR,Intercept]                                  1
## r_Site_ID[YACHOOP,Intercept]                                   1
## r_Site_ID[YONAFR,Intercept]                                    1
## r_Site_ID[CHATANOP,LanduseDeveloped]                           1
## r_Site_ID[GENKAOP,LanduseDeveloped]                            1
## r_Site_ID[GESASHIOP,LanduseDeveloped]                          1
## r_Site_ID[HEIWAOP,LanduseDeveloped]                            1
## r_Site_ID[HENTONAOP,LanduseDeveloped]                          1
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                       1
## r_Site_ID[KEMINFR,LanduseDeveloped]                            1
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                        1
## r_Site_ID[MANABIFR,LanduseDeveloped]                           1
## r_Site_ID[NAGOFR,LanduseDeveloped]                             1
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                       1
## r_Site_ID[OISTFR,LanduseDeveloped]                             1
## r_Site_ID[OISTOP,LanduseDeveloped]                             1
## r_Site_ID[OKUFR,LanduseDeveloped]                              1
## r_Site_ID[OYAMAOP,LanduseDeveloped]                            1
## r_Site_ID[SEFAFR,LanduseDeveloped]                             1
## r_Site_ID[SENBARUOP,LanduseDeveloped]                          1
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                         1
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                       1
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                       1
## r_Site_ID[TOUNANOP,LanduseDeveloped]                           1
## r_Site_ID[UEHARAFR,LanduseDeveloped]                           1
## r_Site_ID[YACHOOP,LanduseDeveloped]                            1
## r_Site_ID[YONAFR,LanduseDeveloped]                             1
## r_Site_ID[CHATANOP,TyphoonPost]                                1
## r_Site_ID[GENKAOP,TyphoonPost]                                 1
## r_Site_ID[GESASHIOP,TyphoonPost]                               1
## r_Site_ID[HEIWAOP,TyphoonPost]                                 1
## r_Site_ID[HENTONAOP,TyphoonPost]                               1
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                            1
## r_Site_ID[KEMINFR,TyphoonPost]                                 1
## r_Site_ID[KURASHIKIOP,TyphoonPost]                             1
## r_Site_ID[MANABIFR,TyphoonPost]                                1
## r_Site_ID[NAGOFR,TyphoonPost]                                  1
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                            1
## r_Site_ID[OISTFR,TyphoonPost]                                  1
## r_Site_ID[OISTOP,TyphoonPost]                                  1
## r_Site_ID[OKUFR,TyphoonPost]                                   1
## r_Site_ID[OYAMAOP,TyphoonPost]                                 1
## r_Site_ID[SEFAFR,TyphoonPost]                                  1
## r_Site_ID[SENBARUOP,TyphoonPost]                               1
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                              1
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                            1
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                            1
## r_Site_ID[TOUNANOP,TyphoonPost]                                1
## r_Site_ID[UEHARAFR,TyphoonPost]                                1
## r_Site_ID[YACHOOP,TyphoonPost]                                 1
## r_Site_ID[YONAFR,TyphoonPost]                                  1
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]            1
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                  1
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]             1
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                 1
## lprior                                                         1
## lp__                                                           1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:29:23 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate Est.Error    Q2.5     Q97.5
## R2 0.7044893 0.1139198 0.49624 0.9131412
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.01199015
## 
## $expected
## [1] -0.0212766
## 
## $sd
## [1] 0.04112041
## 
## $p.value
## [1] 0.8213293

NDSI_Bio - no effect of typhoon or land use

# get pre vs post data for comparison
dat_pre<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Bio" & response_variable %in% 'Pre_Var') 
dat_post<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Bio" & response_variable %in% 'Post_Var')
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
#names(df)[1] <- names(Landuse_1000)[1]
#df <- left_join(df, Landuse_1000, by = "site_id")

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

# fit random intercept and slope model because random slope model didn't converge well.
mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse * Typhoon + (1+Landuse*Typhoon|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
## Warning: There were 111 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 46 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 1b3a3d37e3bf884746f549577180da75.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                                               mean se_mean
## b_Intercept                                                  -0.33    0.00
## b_LanduseDeveloped                                            0.26    0.00
## b_TyphoonPost                                                 0.40    0.00
## b_LanduseDeveloped:TyphoonPost                               -0.10    0.00
## sd_Site_ID__Intercept                                         1.32    0.00
## sd_Site_ID__LanduseDeveloped                                  0.86    0.00
## sd_Site_ID__TyphoonPost                                       1.68    0.00
## sd_Site_ID__LanduseDeveloped:TyphoonPost                      1.53    0.01
## cor_Site_ID__Intercept__LanduseDeveloped                     -0.43    0.00
## cor_Site_ID__Intercept__TyphoonPost                          -0.62    0.00
## cor_Site_ID__LanduseDeveloped__TyphoonPost                    0.30    0.00
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost          0.03    0.00
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost   0.00    0.00
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost       -0.01    0.00
## phi                                                          12.28    0.09
## r_Site_ID[CHATANOP,Intercept]                                 0.06    0.00
## r_Site_ID[GENKAOP,Intercept]                                 -0.29    0.00
## r_Site_ID[GESASHIOP,Intercept]                                0.57    0.00
## r_Site_ID[HEIWAOP,Intercept]                                 -1.42    0.00
## r_Site_ID[HENTONAOP,Intercept]                               -0.01    0.00
## r_Site_ID[KATSUUDAKEFR,Intercept]                             0.12    0.00
## r_Site_ID[KEMINFR,Intercept]                                 -1.10    0.01
## r_Site_ID[KURASHIKIOP,Intercept]                              0.89    0.00
## r_Site_ID[MANABIFR,Intercept]                                 0.34    0.00
## r_Site_ID[NAGOFR,Intercept]                                   0.31    0.00
## r_Site_ID[NAKAGUSUKUFR,Intercept]                             0.25    0.00
## r_Site_ID[OISTFR,Intercept]                                   0.00    0.00
## r_Site_ID[OISTOP,Intercept]                                   0.48    0.01
## r_Site_ID[OKUFR,Intercept]                                   -0.15    0.00
## r_Site_ID[OYAMAOP,Intercept]                                  0.75    0.00
## r_Site_ID[SEFAFR,Intercept]                                  -0.04    0.00
## r_Site_ID[SENBARUOP,Intercept]                                1.14    0.00
## r_Site_ID[SUEYOSHIFR,Intercept]                               1.47    0.00
## r_Site_ID[TAKEYANBARUF,Intercept]                             0.21    0.00
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            -3.68    0.01
## r_Site_ID[TOUNANOP,Intercept]                                 0.81    0.00
## r_Site_ID[UEHARAFR,Intercept]                                -0.33    0.00
## r_Site_ID[YACHOOP,Intercept]                                 -0.78    0.00
## r_Site_ID[YONAFR,Intercept]                                   0.43    0.00
## r_Site_ID[CHATANOP,LanduseDeveloped]                         -0.04    0.00
## r_Site_ID[GENKAOP,LanduseDeveloped]                           0.25    0.00
## r_Site_ID[GESASHIOP,LanduseDeveloped]                        -0.20    0.00
## r_Site_ID[HEIWAOP,LanduseDeveloped]                           0.49    0.00
## r_Site_ID[HENTONAOP,LanduseDeveloped]                         0.21    0.00
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                     -0.01    0.00
## r_Site_ID[KEMINFR,LanduseDeveloped]                          -0.05    0.00
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                      -0.33    0.00
## r_Site_ID[MANABIFR,LanduseDeveloped]                          0.10    0.00
## r_Site_ID[NAGOFR,LanduseDeveloped]                           -0.09    0.00
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                     -0.09    0.00
## r_Site_ID[OISTFR,LanduseDeveloped]                           -0.08    0.00
## r_Site_ID[OISTOP,LanduseDeveloped]                           -0.77    0.01
## r_Site_ID[OKUFR,LanduseDeveloped]                            -0.15    0.00
## r_Site_ID[OYAMAOP,LanduseDeveloped]                          -0.30    0.00
## r_Site_ID[SEFAFR,LanduseDeveloped]                            0.04    0.00
## r_Site_ID[SENBARUOP,LanduseDeveloped]                        -0.42    0.00
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                       -0.51    0.00
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      0.28    0.00
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                      1.37    0.01
## r_Site_ID[TOUNANOP,LanduseDeveloped]                         -0.33    0.00
## r_Site_ID[UEHARAFR,LanduseDeveloped]                          0.11    0.00
## r_Site_ID[YACHOOP,LanduseDeveloped]                           0.29    0.00
## r_Site_ID[YONAFR,LanduseDeveloped]                            0.21    0.00
## r_Site_ID[CHATANOP,TyphoonPost]                              -1.02    0.00
## r_Site_ID[GENKAOP,TyphoonPost]                                0.88    0.01
## r_Site_ID[GESASHIOP,TyphoonPost]                              0.07    0.00
## r_Site_ID[HEIWAOP,TyphoonPost]                               -0.18    0.00
## r_Site_ID[HENTONAOP,TyphoonPost]                              0.48    0.01
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                          -0.17    0.00
## r_Site_ID[KEMINFR,TyphoonPost]                                1.23    0.01
## r_Site_ID[KURASHIKIOP,TyphoonPost]                           -0.73    0.00
## r_Site_ID[MANABIFR,TyphoonPost]                              -0.20    0.00
## r_Site_ID[NAGOFR,TyphoonPost]                                 0.57    0.00
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                           0.08    0.00
## r_Site_ID[OISTFR,TyphoonPost]                                -0.16    0.00
## r_Site_ID[OISTOP,TyphoonPost]                                -2.23    0.01
## r_Site_ID[OKUFR,TyphoonPost]                                 -0.13    0.00
## r_Site_ID[OYAMAOP,TyphoonPost]                               -1.33    0.01
## r_Site_ID[SEFAFR,TyphoonPost]                                 0.94    0.00
## r_Site_ID[SENBARUOP,TyphoonPost]                             -0.62    0.00
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                            -0.41    0.00
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                           0.34    0.01
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                           4.35    0.01
## r_Site_ID[TOUNANOP,TyphoonPost]                              -2.13    0.01
## r_Site_ID[UEHARAFR,TyphoonPost]                              -0.32    0.00
## r_Site_ID[YACHOOP,TyphoonPost]                                0.73    0.00
## r_Site_ID[YONAFR,TyphoonPost]                                -0.07    0.00
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]              0.06    0.01
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]               0.81    0.01
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]             0.00    0.01
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]              -0.02    0.01
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]             0.60    0.00
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]         -0.10    0.00
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]               0.40    0.00
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]           0.07    0.01
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              0.10    0.00
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]               -0.03    0.01
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]          0.00    0.01
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]               -0.21    0.00
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               -2.33    0.01
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                -0.34    0.00
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]               0.10    0.01
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]               -0.05    0.01
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]             0.05    0.01
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]            0.05    0.01
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]          0.65    0.01
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]         -0.32    0.01
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]              0.15    0.01
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]              0.01    0.01
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]              -0.06    0.01
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                0.37    0.00
## lprior                                                      -18.33    0.01
## lp__                                                        -96.42    0.16
##                                                                sd    2.5%
## b_Intercept                                                  0.41   -1.15
## b_LanduseDeveloped                                           0.61   -0.96
## b_TyphoonPost                                                0.54   -0.67
## b_LanduseDeveloped:TyphoonPost                               1.00   -2.09
## sd_Site_ID__Intercept                                        0.32    0.76
## sd_Site_ID__LanduseDeveloped                                 0.58    0.04
## sd_Site_ID__TyphoonPost                                      0.50    0.64
## sd_Site_ID__LanduseDeveloped:TyphoonPost                     0.99    0.08
## cor_Site_ID__Intercept__LanduseDeveloped                     0.42   -0.95
## cor_Site_ID__Intercept__TyphoonPost                          0.21   -0.90
## cor_Site_ID__LanduseDeveloped__TyphoonPost                   0.42   -0.64
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost         0.43   -0.78
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost  0.44   -0.81
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost       0.43   -0.77
## phi                                                          9.55    3.37
## r_Site_ID[CHATANOP,Intercept]                                0.68   -1.33
## r_Site_ID[GENKAOP,Intercept]                                 1.01   -2.42
## r_Site_ID[GESASHIOP,Intercept]                               0.68   -0.77
## r_Site_ID[HEIWAOP,Intercept]                                 0.79   -3.05
## r_Site_ID[HENTONAOP,Intercept]                               0.98   -2.07
## r_Site_ID[KATSUUDAKEFR,Intercept]                            0.94   -1.75
## r_Site_ID[KEMINFR,Intercept]                                 1.11   -3.33
## r_Site_ID[KURASHIKIOP,Intercept]                             0.71   -0.48
## r_Site_ID[MANABIFR,Intercept]                                0.96   -1.64
## r_Site_ID[NAGOFR,Intercept]                                  0.68   -1.04
## r_Site_ID[NAKAGUSUKUFR,Intercept]                            0.68   -1.10
## r_Site_ID[OISTFR,Intercept]                                  0.94   -1.86
## r_Site_ID[OISTOP,Intercept]                                  1.46   -2.11
## r_Site_ID[OKUFR,Intercept]                                   0.96   -2.04
## r_Site_ID[OYAMAOP,Intercept]                                 0.71   -0.65
## r_Site_ID[SEFAFR,Intercept]                                  0.68   -1.41
## r_Site_ID[SENBARUOP,Intercept]                               0.72   -0.26
## r_Site_ID[SUEYOSHIFR,Intercept]                              0.75    0.02
## r_Site_ID[TAKEYANBARUF,Intercept]                            1.02   -1.98
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            0.98   -5.68
## r_Site_ID[TOUNANOP,Intercept]                                0.73   -0.64
## r_Site_ID[UEHARAFR,Intercept]                                0.69   -1.75
## r_Site_ID[YACHOOP,Intercept]                                 0.72   -2.25
## r_Site_ID[YONAFR,Intercept]                                  1.01   -1.68
## r_Site_ID[CHATANOP,LanduseDeveloped]                         0.81   -1.80
## r_Site_ID[GENKAOP,LanduseDeveloped]                          0.86   -1.43
## r_Site_ID[GESASHIOP,LanduseDeveloped]                        0.81   -2.09
## r_Site_ID[HEIWAOP,LanduseDeveloped]                          1.05   -1.26
## r_Site_ID[HENTONAOP,LanduseDeveloped]                        0.83   -1.39
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                     0.78   -1.71
## r_Site_ID[KEMINFR,LanduseDeveloped]                          0.91   -2.19
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                      0.85   -2.36
## r_Site_ID[MANABIFR,LanduseDeveloped]                         0.80   -1.51
## r_Site_ID[NAGOFR,LanduseDeveloped]                           0.81   -1.91
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                     0.77   -1.80
## r_Site_ID[OISTFR,LanduseDeveloped]                           0.78   -1.85
## r_Site_ID[OISTOP,LanduseDeveloped]                           1.36   -4.01
## r_Site_ID[OKUFR,LanduseDeveloped]                            0.81   -2.04
## r_Site_ID[OYAMAOP,LanduseDeveloped]                          0.85   -2.31
## r_Site_ID[SEFAFR,LanduseDeveloped]                           0.81   -1.69
## r_Site_ID[SENBARUOP,LanduseDeveloped]                        0.91   -2.59
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                       1.00   -2.96
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                     0.88   -1.32
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                     1.72   -1.12
## r_Site_ID[TOUNANOP,LanduseDeveloped]                         0.93   -2.51
## r_Site_ID[UEHARAFR,LanduseDeveloped]                         0.80   -1.50
## r_Site_ID[YACHOOP,LanduseDeveloped]                          0.83   -1.22
## r_Site_ID[YONAFR,LanduseDeveloped]                           0.85   -1.39
## r_Site_ID[CHATANOP,TyphoonPost]                              0.97   -2.94
## r_Site_ID[GENKAOP,TyphoonPost]                               1.32   -1.73
## r_Site_ID[GESASHIOP,TyphoonPost]                             0.91   -1.70
## r_Site_ID[HEIWAOP,TyphoonPost]                               0.97   -2.15
## r_Site_ID[HENTONAOP,TyphoonPost]                             1.24   -2.03
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                          1.15   -2.51
## r_Site_ID[KEMINFR,TyphoonPost]                               1.36   -1.35
## r_Site_ID[KURASHIKIOP,TyphoonPost]                           0.93   -2.58
## r_Site_ID[MANABIFR,TyphoonPost]                              1.18   -2.60
## r_Site_ID[NAGOFR,TyphoonPost]                                0.93   -1.23
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                          0.90   -1.68
## r_Site_ID[OISTFR,TyphoonPost]                                1.16   -2.46
## r_Site_ID[OISTOP,TyphoonPost]                                2.09   -6.14
## r_Site_ID[OKUFR,TyphoonPost]                                 1.18   -2.48
## r_Site_ID[OYAMAOP,TyphoonPost]                               0.99   -3.29
## r_Site_ID[SEFAFR,TyphoonPost]                                0.97   -0.89
## r_Site_ID[SENBARUOP,TyphoonPost]                             0.93   -2.47
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                            0.94   -2.25
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                          1.27   -2.25
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                          1.51    0.99
## r_Site_ID[TOUNANOP,TyphoonPost]                              1.13   -4.32
## r_Site_ID[UEHARAFR,TyphoonPost]                              0.92   -2.15
## r_Site_ID[YACHOOP,TyphoonPost]                               0.94   -1.09
## r_Site_ID[YONAFR,TyphoonPost]                                1.22   -2.59
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]             1.70   -3.36
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]              1.28   -1.26
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]            1.63   -3.57
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]              2.01   -4.17
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]            1.20   -1.52
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]         1.10   -2.52
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]              1.26   -1.97
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]          1.64   -3.36
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]             1.12   -2.25
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]               1.68   -3.81
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]         1.58   -3.46
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]               1.11   -2.69
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               2.08   -7.09
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                1.13   -2.90
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]              1.70   -3.29
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]               1.68   -3.87
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]            1.73   -3.63
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]           1.89   -4.06
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]         1.23   -1.51
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]         2.97   -7.29
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]             1.93   -3.55
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]             1.63   -3.37
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]              1.64   -3.71
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]               1.18   -1.92
## lprior                                                       1.29  -21.18
## lp__                                                        16.64 -126.97
##                                                                 25%    50%
## b_Intercept                                                   -0.60  -0.33
## b_LanduseDeveloped                                            -0.14   0.26
## b_TyphoonPost                                                  0.05   0.40
## b_LanduseDeveloped:TyphoonPost                                -0.75  -0.11
## sd_Site_ID__Intercept                                          1.10   1.30
## sd_Site_ID__LanduseDeveloped                                   0.38   0.78
## sd_Site_ID__TyphoonPost                                        1.37   1.67
## sd_Site_ID__LanduseDeveloped:TyphoonPost                       0.77   1.41
## cor_Site_ID__Intercept__LanduseDeveloped                      -0.77  -0.55
## cor_Site_ID__Intercept__TyphoonPost                           -0.76  -0.65
## cor_Site_ID__LanduseDeveloped__TyphoonPost                     0.03   0.38
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost          -0.30   0.04
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost   -0.34   0.00
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost        -0.33  -0.02
## phi                                                            6.38   9.56
## r_Site_ID[CHATANOP,Intercept]                                 -0.38   0.07
## r_Site_ID[GENKAOP,Intercept]                                  -0.89  -0.25
## r_Site_ID[GESASHIOP,Intercept]                                 0.13   0.57
## r_Site_ID[HEIWAOP,Intercept]                                  -1.93  -1.40
## r_Site_ID[HENTONAOP,Intercept]                                -0.60   0.02
## r_Site_ID[KATSUUDAKEFR,Intercept]                             -0.46   0.12
## r_Site_ID[KEMINFR,Intercept]                                  -1.80  -1.10
## r_Site_ID[KURASHIKIOP,Intercept]                               0.43   0.89
## r_Site_ID[MANABIFR,Intercept]                                 -0.25   0.35
## r_Site_ID[NAGOFR,Intercept]                                   -0.13   0.31
## r_Site_ID[NAKAGUSUKUFR,Intercept]                             -0.19   0.25
## r_Site_ID[OISTFR,Intercept]                                   -0.59  -0.01
## r_Site_ID[OISTOP,Intercept]                                   -0.49   0.34
## r_Site_ID[OKUFR,Intercept]                                    -0.75  -0.17
## r_Site_ID[OYAMAOP,Intercept]                                   0.29   0.75
## r_Site_ID[SEFAFR,Intercept]                                   -0.48  -0.03
## r_Site_ID[SENBARUOP,Intercept]                                 0.67   1.14
## r_Site_ID[SUEYOSHIFR,Intercept]                                0.97   1.46
## r_Site_ID[TAKEYANBARUF,Intercept]                             -0.40   0.24
## r_Site_ID[TAMAGUSUKUFR,Intercept]                             -4.32  -3.65
## r_Site_ID[TOUNANOP,Intercept]                                  0.34   0.82
## r_Site_ID[UEHARAFR,Intercept]                                 -0.77  -0.32
## r_Site_ID[YACHOOP,Intercept]                                  -1.24  -0.77
## r_Site_ID[YONAFR,Intercept]                                   -0.19   0.45
## r_Site_ID[CHATANOP,LanduseDeveloped]                          -0.40  -0.02
## r_Site_ID[GENKAOP,LanduseDeveloped]                           -0.16   0.11
## r_Site_ID[GESASHIOP,LanduseDeveloped]                         -0.54  -0.08
## r_Site_ID[HEIWAOP,LanduseDeveloped]                           -0.08   0.25
## r_Site_ID[HENTONAOP,LanduseDeveloped]                         -0.18   0.09
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                      -0.35   0.00
## r_Site_ID[KEMINFR,LanduseDeveloped]                           -0.41   0.00
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                       -0.71  -0.16
## r_Site_ID[MANABIFR,LanduseDeveloped]                          -0.27   0.02
## r_Site_ID[NAGOFR,LanduseDeveloped]                            -0.43  -0.03
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                      -0.40  -0.03
## r_Site_ID[OISTFR,LanduseDeveloped]                            -0.42  -0.03
## r_Site_ID[OISTOP,LanduseDeveloped]                            -1.49  -0.44
## r_Site_ID[OKUFR,LanduseDeveloped]                             -0.48  -0.05
## r_Site_ID[OYAMAOP,LanduseDeveloped]                           -0.68  -0.15
## r_Site_ID[SEFAFR,LanduseDeveloped]                            -0.31   0.01
## r_Site_ID[SENBARUOP,LanduseDeveloped]                         -0.83  -0.22
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                        -0.98  -0.28
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      -0.15   0.11
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                       0.09   0.98
## r_Site_ID[TOUNANOP,LanduseDeveloped]                          -0.77  -0.17
## r_Site_ID[UEHARAFR,LanduseDeveloped]                          -0.25   0.04
## r_Site_ID[YACHOOP,LanduseDeveloped]                           -0.12   0.14
## r_Site_ID[YONAFR,LanduseDeveloped]                            -0.20   0.07
## r_Site_ID[CHATANOP,TyphoonPost]                               -1.66  -1.01
## r_Site_ID[GENKAOP,TyphoonPost]                                 0.04   0.86
## r_Site_ID[GESASHIOP,TyphoonPost]                              -0.52   0.06
## r_Site_ID[HEIWAOP,TyphoonPost]                                -0.80  -0.17
## r_Site_ID[HENTONAOP,TyphoonPost]                              -0.29   0.47
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                           -0.87  -0.15
## r_Site_ID[KEMINFR,TyphoonPost]                                 0.33   1.18
## r_Site_ID[KURASHIKIOP,TyphoonPost]                            -1.33  -0.72
## r_Site_ID[MANABIFR,TyphoonPost]                               -0.92  -0.18
## r_Site_ID[NAGOFR,TyphoonPost]                                 -0.05   0.55
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                           -0.50   0.07
## r_Site_ID[OISTFR,TyphoonPost]                                 -0.88  -0.16
## r_Site_ID[OISTOP,TyphoonPost]                                 -3.69  -2.27
## r_Site_ID[OKUFR,TyphoonPost]                                  -0.85  -0.13
## r_Site_ID[OYAMAOP,TyphoonPost]                                -1.99  -1.33
## r_Site_ID[SEFAFR,TyphoonPost]                                  0.28   0.92
## r_Site_ID[SENBARUOP,TyphoonPost]                              -1.22  -0.61
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                             -1.02  -0.41
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                           -0.43   0.33
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                            3.42   4.42
## r_Site_ID[TOUNANOP,TyphoonPost]                               -2.89  -2.15
## r_Site_ID[UEHARAFR,TyphoonPost]                               -0.91  -0.31
## r_Site_ID[YACHOOP,TyphoonPost]                                 0.11   0.71
## r_Site_ID[YONAFR,TyphoonPost]                                 -0.81  -0.04
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]              -0.71  -0.01
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]                0.00   0.57
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]             -0.68   0.01
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]               -0.96  -0.04
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]             -0.08   0.39
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]          -0.62  -0.04
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]               -0.26   0.24
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]           -0.66   0.01
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              -0.44   0.05
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                -0.70   0.01
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]          -0.66   0.01
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]                -0.74  -0.10
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]                -3.60  -2.05
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                 -0.90  -0.20
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]               -0.68   0.00
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                -0.71   0.01
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]             -0.70   0.01
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]            -0.77   0.03
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]          -0.06   0.44
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]          -1.57  -0.05
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]              -0.77   0.00
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]              -0.72  -0.01
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]               -0.74  -0.01
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                -0.24   0.21
## lprior                                                       -19.13 -18.20
## lp__                                                        -108.05 -97.09
##                                                                75%  97.5% n_eff
## b_Intercept                                                  -0.06   0.49 54155
## b_LanduseDeveloped                                            0.66   1.46 58566
## b_TyphoonPost                                                 0.76   1.48 59184
## b_LanduseDeveloped:TyphoonPost                                0.54   1.89 58961
## sd_Site_ID__Intercept                                         1.52   2.01 22913
## sd_Site_ID__LanduseDeveloped                                  1.24   2.16 33241
## sd_Site_ID__TyphoonPost                                       1.99   2.68 20343
## sd_Site_ID__LanduseDeveloped:TyphoonPost                      2.14   3.76 34691
## cor_Site_ID__Intercept__LanduseDeveloped                     -0.18   0.59 48484
## cor_Site_ID__Intercept__TyphoonPost                          -0.51  -0.12 53106
## cor_Site_ID__LanduseDeveloped__TyphoonPost                    0.63   0.90 27642
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost          0.37   0.81 65966
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost   0.34   0.81 57377
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost        0.32   0.80 56619
## phi                                                          14.89  37.59 11060
## r_Site_ID[CHATANOP,Intercept]                                 0.51   1.38 63838
## r_Site_ID[GENKAOP,Intercept]                                  0.35   1.64 54616
## r_Site_ID[GESASHIOP,Intercept]                                1.01   1.94 57360
## r_Site_ID[HEIWAOP,Intercept]                                 -0.89   0.06 41409
## r_Site_ID[HENTONAOP,Intercept]                                0.61   1.88 61553
## r_Site_ID[KATSUUDAKEFR,Intercept]                             0.69   2.01 70243
## r_Site_ID[KEMINFR,Intercept]                                 -0.41   1.13 42358
## r_Site_ID[KURASHIKIOP,Intercept]                              1.35   2.30 49714
## r_Site_ID[MANABIFR,Intercept]                                 0.94   2.26 67449
## r_Site_ID[NAGOFR,Intercept]                                   0.75   1.65 65896
## r_Site_ID[NAKAGUSUKUFR,Intercept]                             0.68   1.57 65298
## r_Site_ID[OISTFR,Intercept]                                   0.57   1.90 71232
## r_Site_ID[OISTOP,Intercept]                                   1.33   3.72 33054
## r_Site_ID[OKUFR,Intercept]                                    0.44   1.81 68325
## r_Site_ID[OYAMAOP,Intercept]                                  1.21   2.15 45017
## r_Site_ID[SEFAFR,Intercept]                                   0.40   1.30 65954
## r_Site_ID[SENBARUOP,Intercept]                                1.61   2.60 44385
## r_Site_ID[SUEYOSHIFR,Intercept]                               1.96   2.99 39043
## r_Site_ID[TAKEYANBARUF,Intercept]                             0.85   2.15 52647
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            -3.01  -1.84 19731
## r_Site_ID[TOUNANOP,Intercept]                                 1.29   2.22 43669
## r_Site_ID[UEHARAFR,Intercept]                                 0.12   0.98 63796
## r_Site_ID[YACHOOP,Intercept]                                 -0.30   0.60 50561
## r_Site_ID[YONAFR,Intercept]                                   1.07   2.40 61599
## r_Site_ID[CHATANOP,LanduseDeveloped]                          0.30   1.70 57995
## r_Site_ID[GENKAOP,LanduseDeveloped]                           0.64   2.27 51949
## r_Site_ID[GESASHIOP,LanduseDeveloped]                         0.18   1.37 63828
## r_Site_ID[HEIWAOP,LanduseDeveloped]                           0.97   3.05 46050
## r_Site_ID[HENTONAOP,LanduseDeveloped]                         0.57   2.19 57560
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                      0.32   1.68 68597
## r_Site_ID[KEMINFR,LanduseDeveloped]                           0.38   1.76 56474
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                       0.10   1.20 57232
## r_Site_ID[MANABIFR,LanduseDeveloped]                          0.42   1.97 69297
## r_Site_ID[NAGOFR,LanduseDeveloped]                            0.27   1.55 60426
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                      0.25   1.48 67553
## r_Site_ID[OISTFR,LanduseDeveloped]                            0.26   1.55 66456
## r_Site_ID[OISTOP,LanduseDeveloped]                            0.05   1.45 31089
## r_Site_ID[OKUFR,LanduseDeveloped]                             0.22   1.44 65773
## r_Site_ID[OYAMAOP,LanduseDeveloped]                           0.12   1.28 55727
## r_Site_ID[SEFAFR,LanduseDeveloped]                            0.39   1.79 56545
## r_Site_ID[SENBARUOP,LanduseDeveloped]                         0.07   1.12 52192
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                        0.05   1.14 45396
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      0.65   2.41 48020
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                      2.40   5.40 34013
## r_Site_ID[TOUNANOP,LanduseDeveloped]                          0.13   1.40 45071
## r_Site_ID[UEHARAFR,LanduseDeveloped]                          0.44   1.92 67879
## r_Site_ID[YACHOOP,LanduseDeveloped]                           0.65   2.26 63570
## r_Site_ID[YONAFR,LanduseDeveloped]                            0.57   2.27 59861
## r_Site_ID[CHATANOP,TyphoonPost]                              -0.37   0.85 47673
## r_Site_ID[GENKAOP,TyphoonPost]                                1.73   3.49 46609
## r_Site_ID[GESASHIOP,TyphoonPost]                              0.65   1.90 69768
## r_Site_ID[HEIWAOP,TyphoonPost]                                0.45   1.72 67412
## r_Site_ID[HENTONAOP,TyphoonPost]                              1.26   2.95 57122
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                           0.54   2.12 71899
## r_Site_ID[KEMINFR,TyphoonPost]                                2.08   3.99 43674
## r_Site_ID[KURASHIKIOP,TyphoonPost]                           -0.11   1.08 58512
## r_Site_ID[MANABIFR,TyphoonPost]                               0.52   2.14 70602
## r_Site_ID[NAGOFR,TyphoonPost]                                 1.17   2.45 58720
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                           0.65   1.89 69166
## r_Site_ID[OISTFR,TyphoonPost]                                 0.54   2.18 69247
## r_Site_ID[OISTOP,TyphoonPost]                                -0.78   1.91 28369
## r_Site_ID[OKUFR,TyphoonPost]                                  0.59   2.26 68211
## r_Site_ID[OYAMAOP,TyphoonPost]                               -0.66   0.56 39406
## r_Site_ID[SEFAFR,TyphoonPost]                                 1.57   2.91 52974
## r_Site_ID[SENBARUOP,TyphoonPost]                             -0.02   1.22 59681
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                             0.19   1.48 67799
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                           1.14   2.85 54815
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                           5.37   7.11 19068
## r_Site_ID[TOUNANOP,TyphoonPost]                              -1.36   0.08 28983
## r_Site_ID[UEHARAFR,TyphoonPost]                               0.27   1.49 65060
## r_Site_ID[YACHOOP,TyphoonPost]                                1.35   2.62 55594
## r_Site_ID[YONAFR,TyphoonPost]                                 0.70   2.32 68134
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]              0.72   3.94 61966
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]               1.47   3.88 54023
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]             0.74   3.42 71614
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]               0.82   4.46 62883
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]             1.21   3.45 58567
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]          0.44   2.19 69958
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]               1.02   3.28 64725
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]           0.76   3.69 68292
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              0.65   2.53 70809
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                0.74   3.39 61797
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]          0.68   3.33 71099
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]                0.34   1.99 65934
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               -0.67   0.61 34501
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                 0.24   1.86 66713
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]               0.77   4.00 65789
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                0.72   3.32 62250
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]             0.81   3.76 70028
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]            0.91   4.06 68575
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]          1.29   3.56 56924
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]          1.13   5.39 53166
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]              0.88   4.73 54240
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]              0.68   3.64 69825
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]               0.65   3.38 70416
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                0.95   3.07 67368
## lprior                                                      -17.41 -16.18 17903
## lp__                                                        -85.45 -61.98 11404
##                                                             Rhat
## b_Intercept                                                    1
## b_LanduseDeveloped                                             1
## b_TyphoonPost                                                  1
## b_LanduseDeveloped:TyphoonPost                                 1
## sd_Site_ID__Intercept                                          1
## sd_Site_ID__LanduseDeveloped                                   1
## sd_Site_ID__TyphoonPost                                        1
## sd_Site_ID__LanduseDeveloped:TyphoonPost                       1
## cor_Site_ID__Intercept__LanduseDeveloped                       1
## cor_Site_ID__Intercept__TyphoonPost                            1
## cor_Site_ID__LanduseDeveloped__TyphoonPost                     1
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost           1
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost    1
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost         1
## phi                                                            1
## r_Site_ID[CHATANOP,Intercept]                                  1
## r_Site_ID[GENKAOP,Intercept]                                   1
## r_Site_ID[GESASHIOP,Intercept]                                 1
## r_Site_ID[HEIWAOP,Intercept]                                   1
## r_Site_ID[HENTONAOP,Intercept]                                 1
## r_Site_ID[KATSUUDAKEFR,Intercept]                              1
## r_Site_ID[KEMINFR,Intercept]                                   1
## r_Site_ID[KURASHIKIOP,Intercept]                               1
## r_Site_ID[MANABIFR,Intercept]                                  1
## r_Site_ID[NAGOFR,Intercept]                                    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]                              1
## r_Site_ID[OISTFR,Intercept]                                    1
## r_Site_ID[OISTOP,Intercept]                                    1
## r_Site_ID[OKUFR,Intercept]                                     1
## r_Site_ID[OYAMAOP,Intercept]                                   1
## r_Site_ID[SEFAFR,Intercept]                                    1
## r_Site_ID[SENBARUOP,Intercept]                                 1
## r_Site_ID[SUEYOSHIFR,Intercept]                                1
## r_Site_ID[TAKEYANBARUF,Intercept]                              1
## r_Site_ID[TAMAGUSUKUFR,Intercept]                              1
## r_Site_ID[TOUNANOP,Intercept]                                  1
## r_Site_ID[UEHARAFR,Intercept]                                  1
## r_Site_ID[YACHOOP,Intercept]                                   1
## r_Site_ID[YONAFR,Intercept]                                    1
## r_Site_ID[CHATANOP,LanduseDeveloped]                           1
## r_Site_ID[GENKAOP,LanduseDeveloped]                            1
## r_Site_ID[GESASHIOP,LanduseDeveloped]                          1
## r_Site_ID[HEIWAOP,LanduseDeveloped]                            1
## r_Site_ID[HENTONAOP,LanduseDeveloped]                          1
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                       1
## r_Site_ID[KEMINFR,LanduseDeveloped]                            1
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                        1
## r_Site_ID[MANABIFR,LanduseDeveloped]                           1
## r_Site_ID[NAGOFR,LanduseDeveloped]                             1
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                       1
## r_Site_ID[OISTFR,LanduseDeveloped]                             1
## r_Site_ID[OISTOP,LanduseDeveloped]                             1
## r_Site_ID[OKUFR,LanduseDeveloped]                              1
## r_Site_ID[OYAMAOP,LanduseDeveloped]                            1
## r_Site_ID[SEFAFR,LanduseDeveloped]                             1
## r_Site_ID[SENBARUOP,LanduseDeveloped]                          1
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                         1
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                       1
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                       1
## r_Site_ID[TOUNANOP,LanduseDeveloped]                           1
## r_Site_ID[UEHARAFR,LanduseDeveloped]                           1
## r_Site_ID[YACHOOP,LanduseDeveloped]                            1
## r_Site_ID[YONAFR,LanduseDeveloped]                             1
## r_Site_ID[CHATANOP,TyphoonPost]                                1
## r_Site_ID[GENKAOP,TyphoonPost]                                 1
## r_Site_ID[GESASHIOP,TyphoonPost]                               1
## r_Site_ID[HEIWAOP,TyphoonPost]                                 1
## r_Site_ID[HENTONAOP,TyphoonPost]                               1
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                            1
## r_Site_ID[KEMINFR,TyphoonPost]                                 1
## r_Site_ID[KURASHIKIOP,TyphoonPost]                             1
## r_Site_ID[MANABIFR,TyphoonPost]                                1
## r_Site_ID[NAGOFR,TyphoonPost]                                  1
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                            1
## r_Site_ID[OISTFR,TyphoonPost]                                  1
## r_Site_ID[OISTOP,TyphoonPost]                                  1
## r_Site_ID[OKUFR,TyphoonPost]                                   1
## r_Site_ID[OYAMAOP,TyphoonPost]                                 1
## r_Site_ID[SEFAFR,TyphoonPost]                                  1
## r_Site_ID[SENBARUOP,TyphoonPost]                               1
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                              1
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                            1
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                            1
## r_Site_ID[TOUNANOP,TyphoonPost]                                1
## r_Site_ID[UEHARAFR,TyphoonPost]                                1
## r_Site_ID[YACHOOP,TyphoonPost]                                 1
## r_Site_ID[YONAFR,TyphoonPost]                                  1
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]            1
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                  1
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]             1
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                 1
## lprior                                                         1
## lp__                                                           1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:33:58 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate Est.Error      Q2.5     Q97.5
## R2 0.7343529 0.1259734 0.4589802 0.9300482
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.06653623
## 
## $expected
## [1] -0.0212766
## 
## $sd
## [1] 0.04103721
## 
## $p.value
## [1] 0.2700738

NDSI_Anthro - no effect of typhoon or land use

# get pre vs post data for comparison
dat_pre<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Anth" & response_variable %in% 'Pre_Var') 
dat_post<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Anth" & response_variable %in% 'Post_Var')
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
#names(df)[1] <- names(Landuse_1000)[1]
#df <- left_join(df, Landuse_1000, by = "site_id")

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

# fit random intercept and slope model because random slope model didn't converge well.
mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse * Typhoon + (1+Landuse*Typhoon|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
## Warning: There were 17 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 38 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 

mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 1b3a3d37e3bf884746f549577180da75.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                                               mean se_mean
## b_Intercept                                                   0.48    0.00
## b_LanduseDeveloped                                           -0.98    0.00
## b_TyphoonPost                                                -0.73    0.00
## b_LanduseDeveloped:TyphoonPost                                0.34    0.01
## sd_Site_ID__Intercept                                         0.85    0.00
## sd_Site_ID__LanduseDeveloped                                  1.84    0.00
## sd_Site_ID__TyphoonPost                                       1.42    0.00
## sd_Site_ID__LanduseDeveloped:TyphoonPost                      1.89    0.01
## cor_Site_ID__Intercept__LanduseDeveloped                     -0.09    0.00
## cor_Site_ID__Intercept__TyphoonPost                           0.50    0.00
## cor_Site_ID__LanduseDeveloped__TyphoonPost                   -0.22    0.00
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost         -0.12    0.00
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost  -0.29    0.00
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost       -0.04    0.00
## phi                                                          21.23    0.25
## r_Site_ID[CHATANOP,Intercept]                                 0.64    0.00
## r_Site_ID[GENKAOP,Intercept]                                  0.59    0.00
## r_Site_ID[GESASHIOP,Intercept]                               -1.44    0.00
## r_Site_ID[HEIWAOP,Intercept]                                  1.21    0.00
## r_Site_ID[HENTONAOP,Intercept]                               -0.16    0.00
## r_Site_ID[KATSUUDAKEFR,Intercept]                            -0.05    0.00
## r_Site_ID[KEMINFR,Intercept]                                 -0.12    0.00
## r_Site_ID[KURASHIKIOP,Intercept]                             -0.48    0.00
## r_Site_ID[MANABIFR,Intercept]                                -0.38    0.01
## r_Site_ID[NAGOFR,Intercept]                                  -0.59    0.00
## r_Site_ID[NAKAGUSUKUFR,Intercept]                            -0.44    0.00
## r_Site_ID[OISTFR,Intercept]                                  -0.04    0.00
## r_Site_ID[OISTOP,Intercept]                                   0.22    0.00
## r_Site_ID[OKUFR,Intercept]                                   -0.04    0.00
## r_Site_ID[OYAMAOP,Intercept]                                  0.38    0.00
## r_Site_ID[SEFAFR,Intercept]                                  -0.76    0.00
## r_Site_ID[SENBARUOP,Intercept]                                0.28    0.00
## r_Site_ID[SUEYOSHIFR,Intercept]                               0.15    0.00
## r_Site_ID[TAKEYANBARUF,Intercept]                             0.31    0.00
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            -0.28    0.00
## r_Site_ID[TOUNANOP,Intercept]                                 0.16    0.00
## r_Site_ID[UEHARAFR,Intercept]                                 0.72    0.00
## r_Site_ID[YACHOOP,Intercept]                                  0.44    0.00
## r_Site_ID[YONAFR,Intercept]                                  -0.31    0.01
## r_Site_ID[CHATANOP,LanduseDeveloped]                         -0.34    0.01
## r_Site_ID[GENKAOP,LanduseDeveloped]                           1.36    0.01
## r_Site_ID[GESASHIOP,LanduseDeveloped]                         1.14    0.01
## r_Site_ID[HEIWAOP,LanduseDeveloped]                          -0.49    0.01
## r_Site_ID[HENTONAOP,LanduseDeveloped]                         0.09    0.00
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                      0.22    0.00
## r_Site_ID[KEMINFR,LanduseDeveloped]                           0.63    0.00
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                       0.16    0.01
## r_Site_ID[MANABIFR,LanduseDeveloped]                         -3.98    0.01
## r_Site_ID[NAGOFR,LanduseDeveloped]                            0.03    0.01
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                      0.14    0.01
## r_Site_ID[OISTFR,LanduseDeveloped]                            0.24    0.01
## r_Site_ID[OISTOP,LanduseDeveloped]                            0.91    0.00
## r_Site_ID[OKUFR,LanduseDeveloped]                             0.13    0.00
## r_Site_ID[OYAMAOP,LanduseDeveloped]                          -0.03    0.01
## r_Site_ID[SEFAFR,LanduseDeveloped]                            0.48    0.01
## r_Site_ID[SENBARUOP,LanduseDeveloped]                        -0.27    0.01
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                       -0.06    0.01
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      0.91    0.00
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                      0.08    0.01
## r_Site_ID[TOUNANOP,LanduseDeveloped]                          0.02    0.01
## r_Site_ID[UEHARAFR,LanduseDeveloped]                         -0.40    0.01
## r_Site_ID[YACHOOP,LanduseDeveloped]                          -0.46    0.01
## r_Site_ID[YONAFR,LanduseDeveloped]                           -0.59    0.01
## r_Site_ID[CHATANOP,TyphoonPost]                               0.91    0.00
## r_Site_ID[GENKAOP,TyphoonPost]                                0.93    0.01
## r_Site_ID[GESASHIOP,TyphoonPost]                             -3.27    0.01
## r_Site_ID[HEIWAOP,TyphoonPost]                                1.25    0.00
## r_Site_ID[HENTONAOP,TyphoonPost]                             -0.55    0.01
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                          -0.30    0.01
## r_Site_ID[KEMINFR,TyphoonPost]                               -0.78    0.01
## r_Site_ID[KURASHIKIOP,TyphoonPost]                           -0.40    0.00
## r_Site_ID[MANABIFR,TyphoonPost]                               1.39    0.01
## r_Site_ID[NAGOFR,TyphoonPost]                                 0.12    0.00
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                          -0.31    0.00
## r_Site_ID[OISTFR,TyphoonPost]                                -0.30    0.01
## r_Site_ID[OISTOP,TyphoonPost]                                 0.06    0.00
## r_Site_ID[OKUFR,TyphoonPost]                                 -0.23    0.01
## r_Site_ID[OYAMAOP,TyphoonPost]                               -0.01    0.00
## r_Site_ID[SEFAFR,TyphoonPost]                                -1.34    0.00
## r_Site_ID[SENBARUOP,TyphoonPost]                              0.78    0.00
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                             0.14    0.00
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                           0.37    0.01
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                          -0.18    0.00
## r_Site_ID[TOUNANOP,TyphoonPost]                              -0.12    0.00
## r_Site_ID[UEHARAFR,TyphoonPost]                               1.08    0.00
## r_Site_ID[YACHOOP,TyphoonPost]                                1.35    0.00
## r_Site_ID[YONAFR,TyphoonPost]                                -0.59    0.01
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]             -0.31    0.02
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]               0.92    0.01
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]             0.79    0.03
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]              -0.53    0.01
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]            -0.86    0.01
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]         -0.52    0.01
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]              -1.39    0.01
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]           0.21    0.01
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              3.44    0.02
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                0.17    0.02
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]          0.17    0.01
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]               -0.55    0.01
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               -0.25    0.01
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                -0.38    0.01
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]              -0.12    0.01
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                0.38    0.01
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]            -0.16    0.01
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]           -0.08    0.01
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]          0.20    0.01
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]          0.11    0.01
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]             -0.05    0.01
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]             -0.35    0.01
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]              -0.26    0.02
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]               -0.70    0.02
## lprior                                                      -18.81    0.01
## lp__                                                        -77.61    0.18
##                                                                sd    2.5%
## b_Intercept                                                  0.28   -0.07
## b_LanduseDeveloped                                           0.72   -2.42
## b_TyphoonPost                                                0.45   -1.62
## b_LanduseDeveloped:TyphoonPost                               0.95   -1.55
## sd_Site_ID__Intercept                                        0.29    0.37
## sd_Site_ID__LanduseDeveloped                                 0.74    0.41
## sd_Site_ID__TyphoonPost                                      0.44    0.65
## sd_Site_ID__LanduseDeveloped:TyphoonPost                     1.06    0.14
## cor_Site_ID__Intercept__LanduseDeveloped                     0.43   -0.83
## cor_Site_ID__Intercept__TyphoonPost                          0.29   -0.16
## cor_Site_ID__LanduseDeveloped__TyphoonPost                   0.42   -0.86
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost         0.44   -0.85
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost  0.38   -0.88
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost       0.43   -0.82
## phi                                                         14.38    6.11
## r_Site_ID[CHATANOP,Intercept]                                0.45   -0.19
## r_Site_ID[GENKAOP,Intercept]                                 0.92   -1.26
## r_Site_ID[GESASHIOP,Intercept]                               0.59   -2.74
## r_Site_ID[HEIWAOP,Intercept]                                 0.54    0.22
## r_Site_ID[HENTONAOP,Intercept]                               0.71   -1.59
## r_Site_ID[KATSUUDAKEFR,Intercept]                            0.68   -1.42
## r_Site_ID[KEMINFR,Intercept]                                 0.76   -1.62
## r_Site_ID[KURASHIKIOP,Intercept]                             0.43   -1.37
## r_Site_ID[MANABIFR,Intercept]                                1.48   -3.61
## r_Site_ID[NAGOFR,Intercept]                                  0.46   -1.53
## r_Site_ID[NAKAGUSUKUFR,Intercept]                            0.43   -1.31
## r_Site_ID[OISTFR,Intercept]                                  0.68   -1.43
## r_Site_ID[OISTOP,Intercept]                                  0.72   -1.21
## r_Site_ID[OKUFR,Intercept]                                   0.67   -1.39
## r_Site_ID[OYAMAOP,Intercept]                                 0.44   -0.43
## r_Site_ID[SEFAFR,Intercept]                                  0.45   -1.69
## r_Site_ID[SENBARUOP,Intercept]                               0.43   -0.54
## r_Site_ID[SUEYOSHIFR,Intercept]                              0.41   -0.66
## r_Site_ID[TAKEYANBARUF,Intercept]                            0.75   -1.20
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            0.42   -1.13
## r_Site_ID[TOUNANOP,Intercept]                                0.42   -0.65
## r_Site_ID[UEHARAFR,Intercept]                                0.46   -0.12
## r_Site_ID[YACHOOP,Intercept]                                 0.45   -0.42
## r_Site_ID[YONAFR,Intercept]                                  0.76   -1.85
## r_Site_ID[CHATANOP,LanduseDeveloped]                         1.84   -4.31
## r_Site_ID[GENKAOP,LanduseDeveloped]                          1.21   -0.78
## r_Site_ID[GESASHIOP,LanduseDeveloped]                        2.75   -3.99
## r_Site_ID[HEIWAOP,LanduseDeveloped]                          2.17   -5.23
## r_Site_ID[HENTONAOP,LanduseDeveloped]                        1.00   -1.95
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                     0.98   -1.74
## r_Site_ID[KEMINFR,LanduseDeveloped]                          1.04   -1.37
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                      1.77   -3.32
## r_Site_ID[MANABIFR,LanduseDeveloped]                         1.83   -7.66
## r_Site_ID[NAGOFR,LanduseDeveloped]                           1.88   -3.67
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                     1.76   -3.37
## r_Site_ID[OISTFR,LanduseDeveloped]                           0.98   -1.74
## r_Site_ID[OISTOP,LanduseDeveloped]                           1.01   -0.93
## r_Site_ID[OKUFR,LanduseDeveloped]                            0.97   -1.83
## r_Site_ID[OYAMAOP,LanduseDeveloped]                          1.75   -3.75
## r_Site_ID[SEFAFR,LanduseDeveloped]                           1.95   -3.25
## r_Site_ID[SENBARUOP,LanduseDeveloped]                        1.75   -3.97
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                       1.68   -3.56
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                     1.03   -0.98
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                     1.70   -3.33
## r_Site_ID[TOUNANOP,LanduseDeveloped]                         1.69   -3.52
## r_Site_ID[UEHARAFR,LanduseDeveloped]                         1.88   -4.44
## r_Site_ID[YACHOOP,LanduseDeveloped]                          1.89   -4.44
## r_Site_ID[YONAFR,LanduseDeveloped]                           1.07   -2.91
## r_Site_ID[CHATANOP,TyphoonPost]                              0.70   -0.39
## r_Site_ID[GENKAOP,TyphoonPost]                               1.40   -1.96
## r_Site_ID[GESASHIOP,TyphoonPost]                             1.06   -5.40
## r_Site_ID[HEIWAOP,TyphoonPost]                               0.81   -0.24
## r_Site_ID[HENTONAOP,TyphoonPost]                             1.15   -2.88
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                          1.06   -2.45
## r_Site_ID[KEMINFR,TyphoonPost]                               1.28   -3.37
## r_Site_ID[KURASHIKIOP,TyphoonPost]                           0.68   -1.80
## r_Site_ID[MANABIFR,TyphoonPost]                              2.30   -3.05
## r_Site_ID[NAGOFR,TyphoonPost]                                0.70   -1.29
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                          0.67   -1.69
## r_Site_ID[OISTFR,TyphoonPost]                                1.08   -2.48
## r_Site_ID[OISTOP,TyphoonPost]                                1.07   -2.09
## r_Site_ID[OKUFR,TyphoonPost]                                 1.05   -2.35
## r_Site_ID[OYAMAOP,TyphoonPost]                               0.65   -1.32
## r_Site_ID[SEFAFR,TyphoonPost]                                0.78   -2.99
## r_Site_ID[SENBARUOP,TyphoonPost]                             0.67   -0.48
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                            0.64   -1.14
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                          1.12   -1.89
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                          0.66   -1.51
## r_Site_ID[TOUNANOP,TyphoonPost]                              0.64   -1.42
## r_Site_ID[UEHARAFR,TyphoonPost]                              0.72   -0.25
## r_Site_ID[YACHOOP,TyphoonPost]                               0.75   -0.02
## r_Site_ID[YONAFR,TyphoonPost]                                1.21   -3.00
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]             2.04   -4.98
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]              1.59   -1.90
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]            3.19   -4.74
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]              2.37   -5.84
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]            1.36   -3.99
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]         1.25   -3.34
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]              1.50   -4.85
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]          1.91   -3.66
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]             2.56   -0.49
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]               2.06   -4.27
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]         1.90   -3.73
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]               1.27   -3.45
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               1.24   -2.93
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                1.24   -3.15
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]              1.90   -4.18
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]               2.17   -3.69
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]            1.93   -4.56
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]           1.87   -4.08
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]         1.27   -2.36
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]         1.87   -3.79
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]             1.84   -3.96
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]             2.08   -5.10
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]              2.12   -5.19
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]               1.44   -4.01
## lprior                                                       1.12  -21.26
## lp__                                                        15.30 -106.78
##                                                                25%    50%
## b_Intercept                                                   0.30   0.48
## b_LanduseDeveloped                                           -1.44  -0.98
## b_TyphoonPost                                                -1.01  -0.72
## b_LanduseDeveloped:TyphoonPost                               -0.27   0.34
## sd_Site_ID__Intercept                                         0.66   0.81
## sd_Site_ID__LanduseDeveloped                                  1.34   1.81
## sd_Site_ID__TyphoonPost                                       1.12   1.38
## sd_Site_ID__LanduseDeveloped:TyphoonPost                      1.10   1.82
## cor_Site_ID__Intercept__LanduseDeveloped                     -0.42  -0.11
## cor_Site_ID__Intercept__TyphoonPost                           0.33   0.55
## cor_Site_ID__LanduseDeveloped__TyphoonPost                   -0.55  -0.27
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost         -0.47  -0.16
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost  -0.58  -0.33
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost       -0.38  -0.06
## phi                                                          12.07  17.50
## r_Site_ID[CHATANOP,Intercept]                                 0.34   0.62
## r_Site_ID[GENKAOP,Intercept]                                  0.01   0.58
## r_Site_ID[GESASHIOP,Intercept]                               -1.78  -1.41
## r_Site_ID[HEIWAOP,Intercept]                                  0.84   1.19
## r_Site_ID[HENTONAOP,Intercept]                               -0.58  -0.16
## r_Site_ID[KATSUUDAKEFR,Intercept]                            -0.45  -0.05
## r_Site_ID[KEMINFR,Intercept]                                 -0.58  -0.13
## r_Site_ID[KURASHIKIOP,Intercept]                             -0.75  -0.47
## r_Site_ID[MANABIFR,Intercept]                                -1.28  -0.26
## r_Site_ID[NAGOFR,Intercept]                                  -0.89  -0.58
## r_Site_ID[NAKAGUSUKUFR,Intercept]                            -0.71  -0.42
## r_Site_ID[OISTFR,Intercept]                                  -0.44  -0.05
## r_Site_ID[OISTOP,Intercept]                                  -0.21   0.20
## r_Site_ID[OKUFR,Intercept]                                   -0.43  -0.04
## r_Site_ID[OYAMAOP,Intercept]                                  0.09   0.36
## r_Site_ID[SEFAFR,Intercept]                                  -1.04  -0.74
## r_Site_ID[SENBARUOP,Intercept]                                0.00   0.27
## r_Site_ID[SUEYOSHIFR,Intercept]                              -0.11   0.14
## r_Site_ID[TAKEYANBARUF,Intercept]                            -0.14   0.30
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            -0.54  -0.27
## r_Site_ID[TOUNANOP,Intercept]                                -0.10   0.15
## r_Site_ID[UEHARAFR,Intercept]                                 0.41   0.70
## r_Site_ID[YACHOOP,Intercept]                                  0.14   0.42
## r_Site_ID[YONAFR,Intercept]                                  -0.77  -0.30
## r_Site_ID[CHATANOP,LanduseDeveloped]                         -1.38  -0.20
## r_Site_ID[GENKAOP,LanduseDeveloped]                           0.52   1.27
## r_Site_ID[GESASHIOP,LanduseDeveloped]                        -0.62   0.92
## r_Site_ID[HEIWAOP,LanduseDeveloped]                          -1.72  -0.26
## r_Site_ID[HENTONAOP,LanduseDeveloped]                        -0.52   0.08
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                     -0.36   0.19
## r_Site_ID[KEMINFR,LanduseDeveloped]                          -0.03   0.59
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                      -0.85   0.07
## r_Site_ID[MANABIFR,LanduseDeveloped]                         -5.18  -3.96
## r_Site_ID[NAGOFR,LanduseDeveloped]                           -1.05  -0.04
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                     -0.86   0.05
## r_Site_ID[OISTFR,LanduseDeveloped]                           -0.35   0.21
## r_Site_ID[OISTOP,LanduseDeveloped]                            0.23   0.84
## r_Site_ID[OKUFR,LanduseDeveloped]                            -0.45   0.11
## r_Site_ID[OYAMAOP,LanduseDeveloped]                          -0.97   0.02
## r_Site_ID[SEFAFR,LanduseDeveloped]                           -0.70   0.31
## r_Site_ID[SENBARUOP,LanduseDeveloped]                        -1.25  -0.18
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                       -0.99  -0.02
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      0.21   0.84
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                     -0.88   0.03
## r_Site_ID[TOUNANOP,LanduseDeveloped]                         -0.90   0.03
## r_Site_ID[UEHARAFR,LanduseDeveloped]                         -1.48  -0.25
## r_Site_ID[YACHOOP,LanduseDeveloped]                          -1.55  -0.35
## r_Site_ID[YONAFR,LanduseDeveloped]                           -1.22  -0.52
## r_Site_ID[CHATANOP,TyphoonPost]                               0.45   0.88
## r_Site_ID[GENKAOP,TyphoonPost]                                0.07   0.95
## r_Site_ID[GESASHIOP,TyphoonPost]                             -3.95  -3.25
## r_Site_ID[HEIWAOP,TyphoonPost]                                0.71   1.21
## r_Site_ID[HENTONAOP,TyphoonPost]                             -1.25  -0.53
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                          -0.94  -0.29
## r_Site_ID[KEMINFR,TyphoonPost]                               -1.59  -0.75
## r_Site_ID[KURASHIKIOP,TyphoonPost]                           -0.83  -0.38
## r_Site_ID[MANABIFR,TyphoonPost]                              -0.21   1.38
## r_Site_ID[NAGOFR,TyphoonPost]                                -0.34   0.11
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                          -0.73  -0.30
## r_Site_ID[OISTFR,TyphoonPost]                                -0.95  -0.28
## r_Site_ID[OISTOP,TyphoonPost]                                -0.59   0.06
## r_Site_ID[OKUFR,TyphoonPost]                                 -0.85  -0.22
## r_Site_ID[OYAMAOP,TyphoonPost]                               -0.42   0.00
## r_Site_ID[SEFAFR,TyphoonPost]                                -1.82  -1.30
## r_Site_ID[SENBARUOP,TyphoonPost]                              0.33   0.76
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                            -0.27   0.13
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                          -0.29   0.37
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                          -0.59  -0.17
## r_Site_ID[TOUNANOP,TyphoonPost]                              -0.53  -0.11
## r_Site_ID[UEHARAFR,TyphoonPost]                               0.60   1.05
## r_Site_ID[YACHOOP,TyphoonPost]                                0.85   1.32
## r_Site_ID[YONAFR,TyphoonPost]                                -1.33  -0.58
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]             -1.27  -0.10
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]              -0.08   0.70
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]            -1.00   0.21
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]              -1.75  -0.23
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]            -1.61  -0.65
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]         -1.20  -0.36
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]              -2.26  -1.15
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]          -0.73   0.08
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              1.44   3.25
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]               -0.80   0.09
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]         -0.75   0.07
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]               -1.23  -0.37
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]               -0.91  -0.15
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                -1.04  -0.25
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]              -1.04  -0.06
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]               -0.77   0.11
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]            -1.05  -0.02
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]           -0.93  -0.02
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]         -0.48   0.13
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]         -0.79   0.04
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]             -0.94  -0.03
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]             -1.33  -0.11
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]              -1.21  -0.04
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]               -1.45  -0.49
## lprior                                                      -19.50 -18.73
## lp__                                                        -87.99 -77.84
##                                                                75%  97.5% n_eff
## b_Intercept                                                   0.65   1.04 39969
## b_LanduseDeveloped                                           -0.51   0.46 51773
## b_TyphoonPost                                                -0.44   0.16 42360
## b_LanduseDeveloped:TyphoonPost                                0.95   2.24 29687
## sd_Site_ID__Intercept                                         1.00   1.51 19674
## sd_Site_ID__LanduseDeveloped                                  2.29   3.41 28493
## sd_Site_ID__TyphoonPost                                       1.68   2.38 21191
## sd_Site_ID__LanduseDeveloped:TyphoonPost                      2.56   4.16 10957
## cor_Site_ID__Intercept__LanduseDeveloped                      0.23   0.76 28295
## cor_Site_ID__Intercept__TyphoonPost                           0.72   0.92 37739
## cor_Site_ID__LanduseDeveloped__TyphoonPost                    0.07   0.70 30385
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost          0.20   0.76 38114
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost  -0.04   0.54 58399
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost        0.28   0.78 24337
## phi                                                          25.82  59.94  3222
## r_Site_ID[CHATANOP,Intercept]                                 0.92   1.60 51778
## r_Site_ID[GENKAOP,Intercept]                                  1.16   2.45 35699
## r_Site_ID[GESASHIOP,Intercept]                               -1.06  -0.36 48564
## r_Site_ID[HEIWAOP,Intercept]                                  1.55   2.35 23438
## r_Site_ID[HENTONAOP,Intercept]                                0.26   1.28 46109
## r_Site_ID[KATSUUDAKEFR,Intercept]                             0.34   1.31 48092
## r_Site_ID[KEMINFR,Intercept]                                  0.34   1.43 40070
## r_Site_ID[KURASHIKIOP,Intercept]                             -0.20   0.33 56401
## r_Site_ID[MANABIFR,Intercept]                                 0.63   2.26 24156
## r_Site_ID[NAGOFR,Intercept]                                  -0.28   0.25 41123
## r_Site_ID[NAKAGUSUKUFR,Intercept]                            -0.15   0.36 45180
## r_Site_ID[OISTFR,Intercept]                                   0.35   1.38 19957
## r_Site_ID[OISTOP,Intercept]                                   0.64   1.70 43908
## r_Site_ID[OKUFR,Intercept]                                    0.34   1.31 45855
## r_Site_ID[OYAMAOP,Intercept]                                  0.65   1.31 24399
## r_Site_ID[SEFAFR,Intercept]                                  -0.46   0.07 41610
## r_Site_ID[SENBARUOP,Intercept]                                0.54   1.15 57493
## r_Site_ID[SUEYOSHIFR,Intercept]                               0.41   0.99 62701
## r_Site_ID[TAKEYANBARUF,Intercept]                             0.76   1.84 44572
## r_Site_ID[TAMAGUSUKUFR,Intercept]                            -0.01   0.53 63751
## r_Site_ID[TOUNANOP,Intercept]                                 0.42   1.01 54322
## r_Site_ID[UEHARAFR,Intercept]                                 1.00   1.69 46173
## r_Site_ID[YACHOOP,Intercept]                                  0.71   1.39 59294
## r_Site_ID[YONAFR,Intercept]                                   0.14   1.23 21310
## r_Site_ID[CHATANOP,LanduseDeveloped]                          0.74   3.23 46492
## r_Site_ID[GENKAOP,LanduseDeveloped]                           2.11   3.95 43483
## r_Site_ID[GESASHIOP,LanduseDeveloped]                         2.85   6.98 35187
## r_Site_ID[HEIWAOP,LanduseDeveloped]                           0.84   3.50 42484
## r_Site_ID[HENTONAOP,LanduseDeveloped]                         0.70   2.11 52443
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                      0.81   2.23 56787
## r_Site_ID[KEMINFR,LanduseDeveloped]                           1.28   2.79 46625
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                       1.14   3.91 58859
## r_Site_ID[MANABIFR,LanduseDeveloped]                         -2.76  -0.28 21164
## r_Site_ID[NAGOFR,LanduseDeveloped]                            1.05   4.06 47576
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                      1.12   3.89 30861
## r_Site_ID[OISTFR,LanduseDeveloped]                            0.83   2.25 29763
## r_Site_ID[OISTOP,LanduseDeveloped]                            1.52   3.08 49699
## r_Site_ID[OKUFR,LanduseDeveloped]                             0.72   2.10 49880
## r_Site_ID[OYAMAOP,LanduseDeveloped]                           0.96   3.45 61956
## r_Site_ID[SEFAFR,LanduseDeveloped]                            1.60   4.66 46953
## r_Site_ID[SENBARUOP,LanduseDeveloped]                         0.73   3.24 56995
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                        0.88   3.37 60983
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                      1.54   3.11 53004
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                      1.03   3.67 60931
## r_Site_ID[TOUNANOP,LanduseDeveloped]                          0.97   3.45 61492
## r_Site_ID[UEHARAFR,LanduseDeveloped]                          0.72   3.20 45642
## r_Site_ID[YACHOOP,LanduseDeveloped]                           0.64   3.22 49374
## r_Site_ID[YONAFR,LanduseDeveloped]                            0.09   1.43 31182
## r_Site_ID[CHATANOP,TyphoonPost]                               1.35   2.36 55143
## r_Site_ID[GENKAOP,TyphoonPost]                                1.82   3.68 23882
## r_Site_ID[GESASHIOP,TyphoonPost]                             -2.58  -1.19 24311
## r_Site_ID[HEIWAOP,TyphoonPost]                                1.75   2.96 60950
## r_Site_ID[HENTONAOP,TyphoonPost]                              0.16   1.74 41066
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                           0.34   1.84 40582
## r_Site_ID[KEMINFR,TyphoonPost]                                0.04   1.72 29532
## r_Site_ID[KURASHIKIOP,TyphoonPost]                            0.04   0.89 56582
## r_Site_ID[MANABIFR,TyphoonPost]                               2.99   5.76 28078
## r_Site_ID[NAGOFR,TyphoonPost]                                 0.57   1.50 29758
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                           0.12   0.98 50204
## r_Site_ID[OISTFR,TyphoonPost]                                 0.35   1.90 20028
## r_Site_ID[OISTOP,TyphoonPost]                                 0.71   2.22 49908
## r_Site_ID[OKUFR,TyphoonPost]                                  0.40   1.88 34730
## r_Site_ID[OYAMAOP,TyphoonPost]                                0.41   1.29 66031
## r_Site_ID[SEFAFR,TyphoonPost]                                -0.82   0.07 58309
## r_Site_ID[SENBARUOP,TyphoonPost]                              1.21   2.17 55310
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                             0.54   1.40 47840
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                           1.05   2.60 31191
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                           0.24   1.11 39410
## r_Site_ID[TOUNANOP,TyphoonPost]                               0.29   1.13 64400
## r_Site_ID[UEHARAFR,TyphoonPost]                               1.53   2.60 53503
## r_Site_ID[YACHOOP,TyphoonPost]                                1.83   2.92 34917
## r_Site_ID[YONAFR,TyphoonPost]                                 0.14   1.89 12832
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]              0.74   3.62 13234
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]               1.82   4.54 32021
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]             2.30   8.37  8359
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]               0.74   4.00 43929
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]             0.00   1.50 22671
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]          0.18   1.84 24925
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]              -0.28   0.94 22500
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]           1.13   4.37 59068
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]              5.16   8.88 24223
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                1.20   4.49 15106
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]          1.09   4.28 58618
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]                0.17   1.81 17676
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]                0.43   2.25 32230
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                 0.29   2.02 18362
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]               0.79   3.87 54635
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                1.40   5.39 25446
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]             0.81   3.67 19804
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]            0.80   3.77 16956
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]          0.88   2.93 46139
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]          1.00   4.12 31516
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]              0.82   3.84 49941
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]              0.74   3.66 22931
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]               0.84   3.75 11081
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                0.14   1.86  6708
## lprior                                                      -18.03 -16.82  8766
## lp__                                                        -67.62 -46.57  7008
##                                                             Rhat
## b_Intercept                                                    1
## b_LanduseDeveloped                                             1
## b_TyphoonPost                                                  1
## b_LanduseDeveloped:TyphoonPost                                 1
## sd_Site_ID__Intercept                                          1
## sd_Site_ID__LanduseDeveloped                                   1
## sd_Site_ID__TyphoonPost                                        1
## sd_Site_ID__LanduseDeveloped:TyphoonPost                       1
## cor_Site_ID__Intercept__LanduseDeveloped                       1
## cor_Site_ID__Intercept__TyphoonPost                            1
## cor_Site_ID__LanduseDeveloped__TyphoonPost                     1
## cor_Site_ID__Intercept__LanduseDeveloped:TyphoonPost           1
## cor_Site_ID__LanduseDeveloped__LanduseDeveloped:TyphoonPost    1
## cor_Site_ID__TyphoonPost__LanduseDeveloped:TyphoonPost         1
## phi                                                            1
## r_Site_ID[CHATANOP,Intercept]                                  1
## r_Site_ID[GENKAOP,Intercept]                                   1
## r_Site_ID[GESASHIOP,Intercept]                                 1
## r_Site_ID[HEIWAOP,Intercept]                                   1
## r_Site_ID[HENTONAOP,Intercept]                                 1
## r_Site_ID[KATSUUDAKEFR,Intercept]                              1
## r_Site_ID[KEMINFR,Intercept]                                   1
## r_Site_ID[KURASHIKIOP,Intercept]                               1
## r_Site_ID[MANABIFR,Intercept]                                  1
## r_Site_ID[NAGOFR,Intercept]                                    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]                              1
## r_Site_ID[OISTFR,Intercept]                                    1
## r_Site_ID[OISTOP,Intercept]                                    1
## r_Site_ID[OKUFR,Intercept]                                     1
## r_Site_ID[OYAMAOP,Intercept]                                   1
## r_Site_ID[SEFAFR,Intercept]                                    1
## r_Site_ID[SENBARUOP,Intercept]                                 1
## r_Site_ID[SUEYOSHIFR,Intercept]                                1
## r_Site_ID[TAKEYANBARUF,Intercept]                              1
## r_Site_ID[TAMAGUSUKUFR,Intercept]                              1
## r_Site_ID[TOUNANOP,Intercept]                                  1
## r_Site_ID[UEHARAFR,Intercept]                                  1
## r_Site_ID[YACHOOP,Intercept]                                   1
## r_Site_ID[YONAFR,Intercept]                                    1
## r_Site_ID[CHATANOP,LanduseDeveloped]                           1
## r_Site_ID[GENKAOP,LanduseDeveloped]                            1
## r_Site_ID[GESASHIOP,LanduseDeveloped]                          1
## r_Site_ID[HEIWAOP,LanduseDeveloped]                            1
## r_Site_ID[HENTONAOP,LanduseDeveloped]                          1
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]                       1
## r_Site_ID[KEMINFR,LanduseDeveloped]                            1
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]                        1
## r_Site_ID[MANABIFR,LanduseDeveloped]                           1
## r_Site_ID[NAGOFR,LanduseDeveloped]                             1
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]                       1
## r_Site_ID[OISTFR,LanduseDeveloped]                             1
## r_Site_ID[OISTOP,LanduseDeveloped]                             1
## r_Site_ID[OKUFR,LanduseDeveloped]                              1
## r_Site_ID[OYAMAOP,LanduseDeveloped]                            1
## r_Site_ID[SEFAFR,LanduseDeveloped]                             1
## r_Site_ID[SENBARUOP,LanduseDeveloped]                          1
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]                         1
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped]                       1
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]                       1
## r_Site_ID[TOUNANOP,LanduseDeveloped]                           1
## r_Site_ID[UEHARAFR,LanduseDeveloped]                           1
## r_Site_ID[YACHOOP,LanduseDeveloped]                            1
## r_Site_ID[YONAFR,LanduseDeveloped]                             1
## r_Site_ID[CHATANOP,TyphoonPost]                                1
## r_Site_ID[GENKAOP,TyphoonPost]                                 1
## r_Site_ID[GESASHIOP,TyphoonPost]                               1
## r_Site_ID[HEIWAOP,TyphoonPost]                                 1
## r_Site_ID[HENTONAOP,TyphoonPost]                               1
## r_Site_ID[KATSUUDAKEFR,TyphoonPost]                            1
## r_Site_ID[KEMINFR,TyphoonPost]                                 1
## r_Site_ID[KURASHIKIOP,TyphoonPost]                             1
## r_Site_ID[MANABIFR,TyphoonPost]                                1
## r_Site_ID[NAGOFR,TyphoonPost]                                  1
## r_Site_ID[NAKAGUSUKUFR,TyphoonPost]                            1
## r_Site_ID[OISTFR,TyphoonPost]                                  1
## r_Site_ID[OISTOP,TyphoonPost]                                  1
## r_Site_ID[OKUFR,TyphoonPost]                                   1
## r_Site_ID[OYAMAOP,TyphoonPost]                                 1
## r_Site_ID[SEFAFR,TyphoonPost]                                  1
## r_Site_ID[SENBARUOP,TyphoonPost]                               1
## r_Site_ID[SUEYOSHIFR,TyphoonPost]                              1
## r_Site_ID[TAKEYANBARUF,TyphoonPost]                            1
## r_Site_ID[TAMAGUSUKUFR,TyphoonPost]                            1
## r_Site_ID[TOUNANOP,TyphoonPost]                                1
## r_Site_ID[UEHARAFR,TyphoonPost]                                1
## r_Site_ID[YACHOOP,TyphoonPost]                                 1
## r_Site_ID[YONAFR,TyphoonPost]                                  1
## r_Site_ID[CHATANOP,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[GENKAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[GESASHIOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[HEIWAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[HENTONAOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[KEMINFR,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[KURASHIKIOP,LanduseDeveloped:TyphoonPost]            1
## r_Site_ID[MANABIFR,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[NAGOFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[OISTFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[OISTOP,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[OKUFR,LanduseDeveloped:TyphoonPost]                  1
## r_Site_ID[OYAMAOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[SEFAFR,LanduseDeveloped:TyphoonPost]                 1
## r_Site_ID[SENBARUOP,LanduseDeveloped:TyphoonPost]              1
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped:TyphoonPost]             1
## r_Site_ID[TAKEYANBARUF,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped:TyphoonPost]           1
## r_Site_ID[TOUNANOP,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[UEHARAFR,LanduseDeveloped:TyphoonPost]               1
## r_Site_ID[YACHOOP,LanduseDeveloped:TyphoonPost]                1
## r_Site_ID[YONAFR,LanduseDeveloped:TyphoonPost]                 1
## lprior                                                         1
## lp__                                                           1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:40:56 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate  Est.Error      Q2.5     Q97.5
## R2 0.8772635 0.06431607 0.7162266 0.9653288
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.03423118
## 
## $expected
## [1] -0.0212766
## 
## $sd
## [1] 0.0404324
## 
## $p.value
## [1] 0.7486642

acoustic index resistance

NDSI - no effect of land use

# get pre vs post data for comparison
df<-tidy.stability_AI %>%
  filter(Index %in% "NDSI" & response_variable %in% 'Resist') 
df<-df[complete.cases(df),]

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
## Warning: There were 57 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 23 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 516dc2723972b0b4959c45f1ed5792b7.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                     mean se_mean    sd   2.5%    25%    50%
## b_Intercept                         0.66    0.00  0.48  -0.29   0.34   0.65
## b_LanduseDeveloped                  0.04    0.00  0.77  -1.51  -0.46   0.04
## sd_Site_ID__Intercept               1.60    0.00  0.37   0.96   1.34   1.57
## phi                                16.13    0.32 17.38   2.81   6.58  10.87
## r_Site_ID[CHATANOP,Intercept]       0.63    0.00  0.78  -0.85   0.12   0.61
## r_Site_ID[GENKAOP,Intercept]       -0.44    0.00  0.81  -1.99  -0.97  -0.45
## r_Site_ID[GESASHIOP,Intercept]      1.30    0.00  0.85  -0.30   0.73   1.28
## r_Site_ID[HEIWAOP,Intercept]        0.84    0.00  0.80  -0.68   0.31   0.82
## r_Site_ID[HENTONAOP,Intercept]      1.13    0.00  0.89  -0.55   0.53   1.10
## r_Site_ID[KATSUUDAKEFR,Intercept]  -0.01    0.00  0.81  -1.58  -0.54  -0.02
## r_Site_ID[KEMINFR,Intercept]       -0.96    0.00  0.83  -2.57  -1.51  -0.97
## r_Site_ID[KURASHIKIOP,Intercept]    0.25    0.00  0.76  -1.20  -0.24   0.23
## r_Site_ID[MANABIFR,Intercept]       0.07    0.00  0.81  -1.50  -0.47   0.05
## r_Site_ID[NAGOFR,Intercept]         1.22    0.00  0.84  -0.35   0.65   1.19
## r_Site_ID[NAKAGUSUKUFR,Intercept]  -0.46    0.00  0.75  -1.89  -0.95  -0.48
## r_Site_ID[OISTFR,Intercept]         0.44    0.00  0.83  -1.14  -0.11   0.42
## r_Site_ID[OISTOP,Intercept]        -0.84    0.00  0.82  -2.43  -1.37  -0.84
## r_Site_ID[OKUFR,Intercept]         -0.18    0.00  0.81  -1.74  -0.71  -0.19
## r_Site_ID[OYAMAOP,Intercept]        0.43    0.00  0.76  -1.03  -0.07   0.41
## r_Site_ID[SEFAFR,Intercept]        -0.48    0.00  0.75  -1.92  -0.97  -0.49
## r_Site_ID[SENBARUOP,Intercept]      0.27    0.00  0.76  -1.18  -0.23   0.25
## r_Site_ID[SUEYOSHIFR,Intercept]     2.12    0.01  0.96   0.35   1.46   2.07
## r_Site_ID[TAMAGUSUKUFR,Intercept]  -0.95    0.00  0.77  -2.43  -1.45  -0.96
## r_Site_ID[TOUNANOP,Intercept]       0.38    0.00  0.76  -1.07  -0.12   0.36
## r_Site_ID[UEHARAFR,Intercept]      -0.43    0.00  0.75  -1.88  -0.91  -0.44
## r_Site_ID[YACHOOP,Intercept]       -4.99    0.01  1.19  -7.43  -5.76  -4.96
## r_Site_ID[YONAFR,Intercept]         0.91    0.00  0.86  -0.72   0.33   0.89
## lprior                            -10.69    0.01  1.01 -12.97 -11.27 -10.59
## lp__                               -7.65    0.10  9.44 -24.95 -14.22  -8.12
##                                     75% 97.5% n_eff Rhat
## b_Intercept                        0.97  1.63 39091    1
## b_LanduseDeveloped                 0.55  1.55 37326    1
## sd_Site_ID__Intercept              1.83  2.42 19000    1
## phi                               18.97 62.28  3041    1
## r_Site_ID[CHATANOP,Intercept]      1.12  2.24 54239    1
## r_Site_ID[GENKAOP,Intercept]       0.08  1.19 47576    1
## r_Site_ID[GESASHIOP,Intercept]     1.85  3.06 44418    1
## r_Site_ID[HEIWAOP,Intercept]       1.34  2.48 52281    1
## r_Site_ID[HENTONAOP,Intercept]     1.69  2.97 41639    1
## r_Site_ID[KATSUUDAKEFR,Intercept]  0.51  1.63 49696    1
## r_Site_ID[KEMINFR,Intercept]      -0.43  0.70 42813    1
## r_Site_ID[KURASHIKIOP,Intercept]   0.73  1.84 58886    1
## r_Site_ID[MANABIFR,Intercept]      0.59  1.72 48155    1
## r_Site_ID[NAGOFR,Intercept]        1.75  2.94 43537    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]  0.01  1.07 53911    1
## r_Site_ID[OISTFR,Intercept]        0.97  2.13 48141    1
## r_Site_ID[OISTOP,Intercept]       -0.31  0.80 43900    1
## r_Site_ID[OKUFR,Intercept]         0.33  1.44 49247    1
## r_Site_ID[OYAMAOP,Intercept]       0.91  2.01 56413    1
## r_Site_ID[SEFAFR,Intercept]        0.00  1.06 54620    1
## r_Site_ID[SENBARUOP,Intercept]     0.74  1.83 55595    1
## r_Site_ID[SUEYOSHIFR,Intercept]    2.74  4.14 26531    1
## r_Site_ID[TAMAGUSUKUFR,Intercept] -0.45  0.63 48712    1
## r_Site_ID[TOUNANOP,Intercept]      0.86  1.95 56863    1
## r_Site_ID[UEHARAFR,Intercept]      0.04  1.10 52574    1
## r_Site_ID[YACHOOP,Intercept]      -4.19 -2.74 15238    1
## r_Site_ID[YONAFR,Intercept]        1.46  2.69 45666    1
## lprior                            -9.99 -9.02  7599    1
## lp__                              -1.46 12.01  9851    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:43:20 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate Est.Error      Q2.5     Q97.5
## R2 0.7788499 0.1228608 0.5023151 0.9590089
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.07751008
## 
## $expected
## [1] -0.04545455
## 
## $sd
## [1] 0.08880647
## 
## $p.value
## [1] 0.7181298

NDSI_Bio - no effect of land use

# get pre vs post data for comparison
df<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Bio" & response_variable %in% 'Resist') 
df<-df[complete.cases(df),]

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
## Warning: There were 102 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: There were 3 chains where the estimated Bayesian Fraction of Missing Information was low. See
## https://mc-stan.org/misc/warnings.html#bfmi-low
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 23 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 516dc2723972b0b4959c45f1ed5792b7.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                     mean se_mean    sd   2.5%    25%    50%
## b_Intercept                         0.10    0.00  0.55  -0.98  -0.26   0.09
## b_LanduseDeveloped                  0.57    0.01  0.89  -1.17  -0.01   0.56
## sd_Site_ID__Intercept               1.85    0.01  0.49   0.95   1.53   1.83
## phi                                16.86    0.44 20.44   1.92   5.25   9.93
## r_Site_ID[CHATANOP,Intercept]       1.87    0.01  1.01  -0.06   1.19   1.85
## r_Site_ID[GENKAOP,Intercept]       -0.05    0.01  0.90  -1.81  -0.65  -0.07
## r_Site_ID[GESASHIOP,Intercept]      0.55    0.00  0.83  -1.07   0.01   0.54
## r_Site_ID[HEIWAOP,Intercept]        1.39    0.01  0.92  -0.40   0.78   1.38
## r_Site_ID[HENTONAOP,Intercept]     -1.94    0.01  1.04  -3.97  -2.63  -1.95
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.23    0.01  0.91  -1.54  -0.37   0.22
## r_Site_ID[KEMINFR,Intercept]       -0.69    0.01  0.91  -2.47  -1.29  -0.69
## r_Site_ID[KURASHIKIOP,Intercept]    0.28    0.00  0.82  -1.33  -0.25   0.28
## r_Site_ID[MANABIFR,Intercept]       0.96    0.01  0.98  -0.89   0.31   0.93
## r_Site_ID[NAGOFR,Intercept]        -0.54    0.00  0.83  -2.19  -1.07  -0.54
## r_Site_ID[NAKAGUSUKUFR,Intercept]   0.57    0.00  0.83  -1.06   0.03   0.57
## r_Site_ID[OISTFR,Intercept]        -0.22    0.01  0.91  -1.98  -0.81  -0.23
## r_Site_ID[OISTOP,Intercept]         0.85    0.01  0.96  -0.97   0.20   0.82
## r_Site_ID[OKUFR,Intercept]          0.99    0.01  0.98  -0.87   0.33   0.96
## r_Site_ID[OYAMAOP,Intercept]        1.17    0.01  0.89  -0.55   0.58   1.17
## r_Site_ID[SEFAFR,Intercept]        -4.60    0.01  1.35  -7.27  -5.50  -4.58
## r_Site_ID[SENBARUOP,Intercept]      2.98    0.01  1.21   0.72   2.15   2.93
## r_Site_ID[SUEYOSHIFR,Intercept]     0.79    0.00  0.85  -0.88   0.24   0.79
## r_Site_ID[TAMAGUSUKUFR,Intercept]  -1.98    0.01  1.02  -3.98  -2.64  -1.99
## r_Site_ID[TOUNANOP,Intercept]       0.19    0.00  0.81  -1.41  -0.34   0.18
## r_Site_ID[UEHARAFR,Intercept]      -2.41    0.01  1.10  -4.58  -3.14  -2.42
## r_Site_ID[YACHOOP,Intercept]       -0.03    0.00  0.81  -1.64  -0.55  -0.03
## r_Site_ID[YONAFR,Intercept]         0.02    0.01  0.90  -1.73  -0.58   0.01
## lprior                            -10.66    0.02  1.23 -13.48 -11.40 -10.55
## lp__                               -5.98    0.15 11.00 -26.09 -13.71  -6.45
##                                     75% 97.5% n_eff Rhat
## b_Intercept                        0.45  1.20 24949    1
## b_LanduseDeveloped                 1.14  2.34 22202    1
## sd_Site_ID__Intercept              2.15  2.89  7181    1
## phi                               19.76 77.70  2185    1
## r_Site_ID[CHATANOP,Intercept]      2.53  3.89 18188    1
## r_Site_ID[GENKAOP,Intercept]       0.52  1.77 24213    1
## r_Site_ID[GESASHIOP,Intercept]     1.08  2.20 31930    1
## r_Site_ID[HEIWAOP,Intercept]       1.99  3.21 24679    1
## r_Site_ID[HENTONAOP,Intercept]    -1.25  0.13 21629    1
## r_Site_ID[KATSUUDAKEFR,Intercept]  0.81  2.09 24358    1
## r_Site_ID[KEMINFR,Intercept]      -0.10  1.14 25190    1
## r_Site_ID[KURASHIKIOP,Intercept]   0.81  1.92 42903    1
## r_Site_ID[MANABIFR,Intercept]      1.59  2.97 23867    1
## r_Site_ID[NAGOFR,Intercept]        0.00  1.10 41656    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]  1.11  2.26 38836    1
## r_Site_ID[OISTFR,Intercept]        0.36  1.61 27779    1
## r_Site_ID[OISTOP,Intercept]        1.47  2.81 23772    1
## r_Site_ID[OKUFR,Intercept]         1.62  2.98 24971    1
## r_Site_ID[OYAMAOP,Intercept]       1.74  2.96 28678    1
## r_Site_ID[SEFAFR,Intercept]       -3.68 -2.02 10581    1
## r_Site_ID[SENBARUOP,Intercept]     3.77  5.49 11749    1
## r_Site_ID[SUEYOSHIFR,Intercept]    1.34  2.49 36915    1
## r_Site_ID[TAMAGUSUKUFR,Intercept] -1.32  0.04 24999    1
## r_Site_ID[TOUNANOP,Intercept]      0.70  1.80 40779    1
## r_Site_ID[UEHARAFR,Intercept]     -1.69 -0.25 18085    1
## r_Site_ID[YACHOOP,Intercept]       0.49  1.57 41825    1
## r_Site_ID[YONAFR,Intercept]        0.60  1.83 25486    1
## lprior                            -9.78 -8.60  4518    1
## lp__                               1.36 16.94  5310    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:44:29 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate Est.Error      Q2.5     Q97.5
## R2 0.8037031 0.1551114 0.4065787 0.9806057
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.1606967
## 
## $expected
## [1] -0.04545455
## 
## $sd
## [1] 0.08684368
## 
## $p.value
## [1] 0.1845066

NDSI_Anthro - no effect of land use

# get pre vs post data for comparison
df<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Anth" & response_variable %in% 'Resist') 
df<-df[complete.cases(df),]

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
## Warning: There were 90 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 23 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 516dc2723972b0b4959c45f1ed5792b7.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                     mean se_mean    sd   2.5%    25%    50%
## b_Intercept                         0.20    0.00  0.48  -0.73  -0.11   0.20
## b_LanduseDeveloped                  0.30    0.00  0.77  -1.21  -0.20   0.30
## sd_Site_ID__Intercept               1.59    0.00  0.38   0.91   1.33   1.57
## phi                                16.79    0.32 18.02   2.58   6.26  10.91
## r_Site_ID[CHATANOP,Intercept]      -0.25    0.00  0.73  -1.70  -0.73  -0.26
## r_Site_ID[GENKAOP,Intercept]       -0.44    0.00  0.80  -2.02  -0.96  -0.44
## r_Site_ID[GESASHIOP,Intercept]      0.25    0.00  0.74  -1.20  -0.23   0.24
## r_Site_ID[HEIWAOP,Intercept]        1.38    0.00  0.83  -0.22   0.83   1.37
## r_Site_ID[HENTONAOP,Intercept]      0.28    0.00  0.81  -1.29  -0.25   0.27
## r_Site_ID[KATSUUDAKEFR,Intercept]  -1.16    0.00  0.84  -2.82  -1.71  -1.17
## r_Site_ID[KEMINFR,Intercept]        0.95    0.00  0.86  -0.68   0.38   0.94
## r_Site_ID[KURASHIKIOP,Intercept]   -0.29    0.00  0.74  -1.74  -0.77  -0.30
## r_Site_ID[MANABIFR,Intercept]      -1.14    0.01  0.84  -2.82  -1.69  -1.14
## r_Site_ID[NAGOFR,Intercept]        -1.32    0.00  0.82  -2.93  -1.85  -1.33
## r_Site_ID[NAKAGUSUKUFR,Intercept]   1.65    0.00  0.88  -0.04   1.06   1.63
## r_Site_ID[OISTFR,Intercept]        -0.15    0.00  0.80  -1.72  -0.67  -0.15
## r_Site_ID[OISTOP,Intercept]         1.31    0.00  0.90  -0.40   0.71   1.29
## r_Site_ID[OKUFR,Intercept]          0.05    0.00  0.81  -1.53  -0.48   0.04
## r_Site_ID[OYAMAOP,Intercept]        1.11    0.00  0.80  -0.44   0.59   1.10
## r_Site_ID[SEFAFR,Intercept]         0.10    0.00  0.73  -1.34  -0.37   0.09
## r_Site_ID[SENBARUOP,Intercept]     -0.87    0.00  0.77  -2.37  -1.36  -0.87
## r_Site_ID[SUEYOSHIFR,Intercept]    -0.31    0.00  0.74  -1.77  -0.79  -0.31
## r_Site_ID[TAMAGUSUKUFR,Intercept]   1.45    0.00  0.84  -0.18   0.89   1.44
## r_Site_ID[TOUNANOP,Intercept]       0.44    0.00  0.75  -1.02  -0.05   0.43
## r_Site_ID[UEHARAFR,Intercept]       1.36    0.00  0.83  -0.26   0.80   1.35
## r_Site_ID[YACHOOP,Intercept]       -4.58    0.01  1.20  -6.99  -5.37  -4.56
## r_Site_ID[YONAFR,Intercept]         0.31    0.00  0.81  -1.26  -0.22   0.30
## lprior                            -10.66    0.01  1.06 -13.05 -11.30 -10.56
## lp__                               -8.95    0.11 10.06 -27.44 -16.07  -9.39
##                                     75% 97.5% n_eff Rhat
## b_Intercept                        0.51  1.15 37382    1
## b_LanduseDeveloped                 0.80  1.84 27065    1
## sd_Site_ID__Intercept              1.83  2.42 15403    1
## phi                               20.15 67.90  3248    1
## r_Site_ID[CHATANOP,Intercept]      0.22  1.21 54556    1
## r_Site_ID[GENKAOP,Intercept]       0.08  1.17 37123    1
## r_Site_ID[GESASHIOP,Intercept]     0.72  1.73 54220    1
## r_Site_ID[HEIWAOP,Intercept]       1.92  3.08 35682    1
## r_Site_ID[HENTONAOP,Intercept]     0.80  1.92 38900    1
## r_Site_ID[KATSUUDAKEFR,Intercept] -0.61  0.53 29879    1
## r_Site_ID[KEMINFR,Intercept]       1.50  2.70 40529    1
## r_Site_ID[KURASHIKIOP,Intercept]   0.18  1.18 52243    1
## r_Site_ID[MANABIFR,Intercept]     -0.60  0.54 27794    1
## r_Site_ID[NAGOFR,Intercept]       -0.80  0.32 40008    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]  2.22  3.41 31968    1
## r_Site_ID[OISTFR,Intercept]        0.37  1.47 32720    1
## r_Site_ID[OISTOP,Intercept]        1.89  3.17 37156    1
## r_Site_ID[OKUFR,Intercept]         0.56  1.66 38228    1
## r_Site_ID[OYAMAOP,Intercept]       1.62  2.72 43373    1
## r_Site_ID[SEFAFR,Intercept]        0.57  1.58 52309    1
## r_Site_ID[SENBARUOP,Intercept]    -0.37  0.66 46486    1
## r_Site_ID[SUEYOSHIFR,Intercept]    0.16  1.16 52892    1
## r_Site_ID[TAMAGUSUKUFR,Intercept]  1.99  3.15 35619    1
## r_Site_ID[TOUNANOP,Intercept]      0.91  1.94 50209    1
## r_Site_ID[UEHARAFR,Intercept]      1.89  3.04 35614    1
## r_Site_ID[YACHOOP,Intercept]      -3.77 -2.29 13745    1
## r_Site_ID[YONAFR,Intercept]        0.83  1.94 38225    1
## lprior                            -9.91 -8.89  6793    1
## lp__                              -2.19 11.60  8502    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:45:32 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate Est.Error      Q2.5     Q97.5
## R2 0.7788142 0.1466721 0.4306832 0.9682682
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.1208245
## 
## $expected
## [1] -0.04545455
## 
## $sd
## [1] 0.08851953
## 
## $p.value
## [1] 0.3945194

acoustic index recovery time

NDSI - no effect of land use

# get pre vs post data for comparison
df<-tidy.stability_AI %>%
  filter(Index %in% "NDSI" & response_variable %in% 'Recov') 
df<-df[complete.cases(df),]

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
## Warning: There were 31 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 20 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 516dc2723972b0b4959c45f1ed5792b7.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                     mean se_mean    sd   2.5%    25%    50%
## b_Intercept                         0.94    0.00  0.52  -0.08   0.60   0.93
## b_LanduseDeveloped                  0.66    0.00  0.89  -1.10   0.08   0.66
## sd_Site_ID__Intercept               1.70    0.00  0.38   1.06   1.43   1.66
## phi                                24.03    0.25 22.71   3.97  10.54  17.42
## r_Site_ID[CHATANOP,Intercept]       0.87    0.00  0.79  -0.62   0.34   0.85
## r_Site_ID[GESASHIOP,Intercept]      0.87    0.00  0.79  -0.62   0.34   0.84
## r_Site_ID[HEIWAOP,Intercept]        0.87    0.00  0.79  -0.63   0.35   0.85
## r_Site_ID[HENTONAOP,Intercept]      0.33    0.00  0.91  -1.39  -0.27   0.30
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.33    0.00  0.90  -1.39  -0.27   0.30
## r_Site_ID[KEMINFR,Intercept]       -1.04    0.00  0.86  -2.70  -1.60  -1.05
## r_Site_ID[KURASHIKIOP,Intercept]   -0.24    0.00  0.72  -1.62  -0.71  -0.25
## r_Site_ID[NAGOFR,Intercept]         0.87    0.00  0.79  -0.60   0.35   0.85
## r_Site_ID[NAKAGUSUKUFR,Intercept]   0.13    0.00  0.73  -1.26  -0.35   0.11
## r_Site_ID[OISTFR,Intercept]         0.33    0.00  0.90  -1.39  -0.28   0.30
## r_Site_ID[OISTOP,Intercept]         0.18    0.00  0.89  -1.51  -0.42   0.16
## r_Site_ID[OKUFR,Intercept]         -0.22    0.00  0.87  -1.89  -0.80  -0.25
## r_Site_ID[OYAMAOP,Intercept]        0.88    0.00  0.79  -0.62   0.35   0.85
## r_Site_ID[SEFAFR,Intercept]         0.03    0.00  0.73  -1.36  -0.45   0.01
## r_Site_ID[SENBARUOP,Intercept]     -5.68    0.01  1.15  -7.98  -6.42  -5.67
## r_Site_ID[SUEYOSHIFR,Intercept]     0.87    0.00  0.79  -0.62   0.35   0.85
## r_Site_ID[TAMAGUSUKUFR,Intercept]  -0.43    0.00  0.72  -1.80  -0.90  -0.45
## r_Site_ID[TOUNANOP,Intercept]       0.87    0.00  0.79  -0.62   0.34   0.84
## r_Site_ID[UEHARAFR,Intercept]       0.55    0.00  0.76  -0.91   0.04   0.53
## r_Site_ID[YONAFR,Intercept]         0.33    0.00  0.90  -1.39  -0.27   0.30
## lprior                            -11.32    0.01  1.04 -13.60 -11.92 -11.25
## lp__                               -0.69    0.07  8.10 -16.49  -6.16  -0.76
##                                      75% 97.5% n_eff Rhat
## b_Intercept                         1.28  1.97 35567    1
## b_LanduseDeveloped                  1.23  2.43 38487    1
## sd_Site_ID__Intercept               1.93  2.57 25720    1
## phi                                29.20 85.29  8303    1
## r_Site_ID[CHATANOP,Intercept]       1.37  2.51 47014    1
## r_Site_ID[GESASHIOP,Intercept]      1.37  2.50 47589    1
## r_Site_ID[HEIWAOP,Intercept]        1.37  2.49 48947    1
## r_Site_ID[HENTONAOP,Intercept]      0.90  2.20 48481    1
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.90  2.19 51005    1
## r_Site_ID[KEMINFR,Intercept]       -0.49  0.71 46018    1
## r_Site_ID[KURASHIKIOP,Intercept]    0.22  1.24 47422    1
## r_Site_ID[NAGOFR,Intercept]         1.37  2.52 49150    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]   0.59  1.62 47490    1
## r_Site_ID[OISTFR,Intercept]         0.90  2.20 50264    1
## r_Site_ID[OISTOP,Intercept]         0.74  2.03 48917    1
## r_Site_ID[OKUFR,Intercept]          0.33  1.57 49696    1
## r_Site_ID[OYAMAOP,Intercept]        1.38  2.51 48177    1
## r_Site_ID[SEFAFR,Intercept]         0.49  1.53 50427    1
## r_Site_ID[SENBARUOP,Intercept]     -4.93 -3.44 22477    1
## r_Site_ID[SUEYOSHIFR,Intercept]     1.37  2.50 49378    1
## r_Site_ID[TAMAGUSUKUFR,Intercept]   0.02  1.04 46817    1
## r_Site_ID[TOUNANOP,Intercept]       1.37  2.49 48201    1
## r_Site_ID[UEHARAFR,Intercept]       1.03  2.12 49956    1
## r_Site_ID[YONAFR,Intercept]         0.90  2.19 50542    1
## lprior                            -10.63 -9.48 13130    1
## lp__                                4.67 15.55 13542    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:46:32 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate  Est.Error      Q2.5     Q97.5
## R2 0.8553803 0.08716908 0.6421023 0.9718465
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.1500793
## 
## $expected
## [1] -0.05263158
## 
## $sd
## [1] 0.09605959
## 
## $p.value
## [1] 0.3103677

NDSI_Bio - no effect of land use

# get pre vs post data for comparison
df<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Bio" & response_variable %in% 'Recov') 
df<-df[complete.cases(df),]

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Start sampling
## Warning: There were 14 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 17 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 516dc2723972b0b4959c45f1ed5792b7.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                     mean se_mean    sd   2.5%    25%    50%
## b_Intercept                         0.91    0.00  0.59  -0.26   0.53   0.91
## b_LanduseDeveloped                  1.62    0.01  0.96  -0.25   1.00   1.61
## sd_Site_ID__Intercept               1.90    0.00  0.42   1.19   1.61   1.86
## phi                                37.09    0.25 32.93   5.05  15.65  27.51
## r_Site_ID[CHATANOP,Intercept]       1.73    0.00  0.89   0.06   1.14   1.70
## r_Site_ID[GENKAOP,Intercept]        0.35    0.00  0.98  -1.48  -0.31   0.32
## r_Site_ID[GESASHIOP,Intercept]      0.76    0.00  0.78  -0.72   0.25   0.74
## r_Site_ID[HEIWAOP,Intercept]        1.73    0.00  0.89   0.06   1.13   1.70
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.35    0.00  0.98  -1.47  -0.30   0.32
## r_Site_ID[KEMINFR,Intercept]        0.35    0.00  0.99  -1.49  -0.31   0.31
## r_Site_ID[KURASHIKIOP,Intercept]    0.46    0.00  0.76  -0.99  -0.04   0.44
## r_Site_ID[MANABIFR,Intercept]       0.35    0.00  0.98  -1.48  -0.31   0.31
## r_Site_ID[NAGOFR,Intercept]        -6.17    0.01  1.20  -8.58  -6.96  -6.17
## r_Site_ID[NAKAGUSUKUFR,Intercept]   1.72    0.00  0.89   0.05   1.12   1.70
## r_Site_ID[OISTFR,Intercept]        -0.64    0.00  0.93  -2.40  -1.26  -0.67
## r_Site_ID[OISTOP,Intercept]         0.35    0.00  0.98  -1.49  -0.31   0.31
## r_Site_ID[OKUFR,Intercept]          0.35    0.00  0.98  -1.48  -0.31   0.32
## r_Site_ID[SENBARUOP,Intercept]     -0.33    0.00  0.73  -1.74  -0.81  -0.34
## r_Site_ID[SUEYOSHIFR,Intercept]    -0.68    0.00  0.72  -2.09  -1.15  -0.69
## r_Site_ID[TAMAGUSUKUFR,Intercept]   0.43    0.00  0.76  -1.02  -0.07   0.41
## r_Site_ID[TOUNANOP,Intercept]       0.99    0.00  0.80  -0.52   0.45   0.96
## r_Site_ID[UEHARAFR,Intercept]       0.32    0.00  0.75  -1.12  -0.18   0.30
## r_Site_ID[YACHOOP,Intercept]       -0.30    0.00  0.73  -1.71  -0.78  -0.31
## r_Site_ID[YONAFR,Intercept]        -1.01    0.00  0.92  -2.75  -1.62  -1.04
## lprior                            -12.04    0.01  1.20 -14.62 -12.77 -11.99
## lp__                                7.05    0.07  8.27  -9.49   1.50   7.20
##                                      75%  97.5% n_eff Rhat
## b_Intercept                         1.30   2.08 33381    1
## b_LanduseDeveloped                  2.24   3.54 36152    1
## sd_Site_ID__Intercept               2.15   2.85 22197    1
## phi                                47.23 127.07 17827    1
## r_Site_ID[CHATANOP,Intercept]       2.29   3.57 40609    1
## r_Site_ID[GENKAOP,Intercept]        0.96   2.41 51216    1
## r_Site_ID[GESASHIOP,Intercept]      1.26   2.37 43678    1
## r_Site_ID[HEIWAOP,Intercept]        2.29   3.58 39848    1
## r_Site_ID[KATSUUDAKEFR,Intercept]   0.97   2.37 49854    1
## r_Site_ID[KEMINFR,Intercept]        0.96   2.41 50344    1
## r_Site_ID[KURASHIKIOP,Intercept]    0.94   2.00 42665    1
## r_Site_ID[MANABIFR,Intercept]       0.96   2.40 50556    1
## r_Site_ID[NAGOFR,Intercept]        -5.38  -3.81 23631    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]   2.28   3.56 40630    1
## r_Site_ID[OISTFR,Intercept]        -0.06   1.27 44830    1
## r_Site_ID[OISTOP,Intercept]         0.97   2.40 49403    1
## r_Site_ID[OKUFR,Intercept]          0.97   2.40 49401    1
## r_Site_ID[SENBARUOP,Intercept]      0.13   1.13 41083    1
## r_Site_ID[SUEYOSHIFR,Intercept]    -0.22   0.77 40480    1
## r_Site_ID[TAMAGUSUKUFR,Intercept]   0.91   1.97 41933    1
## r_Site_ID[TOUNANOP,Intercept]       1.49   2.62 42276    1
## r_Site_ID[UEHARAFR,Intercept]       0.79   1.86 42835    1
## r_Site_ID[YACHOOP,Intercept]        0.16   1.17 41732    1
## r_Site_ID[YONAFR,Intercept]        -0.43   0.88 41219    1
## lprior                            -11.24  -9.83 16284    1
## lp__                               12.75  22.77 14012    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:47:40 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate  Est.Error      Q2.5     Q97.5
## R2 0.9189229 0.06547899 0.7403166 0.9877987
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.09784212
## 
## $expected
## [1] -0.05263158
## 
## $sd
## [1] 0.1062802
## 
## $p.value
## [1] 0.6705522

NDSI_Anthro - no effect of land use

# get pre vs post data for comparison
df<-tidy.stability_AI %>%
  filter(Index %in% "NDSI_Anth" & response_variable %in% 'Recov') 
df<-df[complete.cases(df),]

# change levels for model
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
#df$site_id<-df$site_id %>% parse_character() %>% parse_factor(levels = c(df$site_id[order(df$PC1)]))

# fit random intercept and slope model because random slope model didn't converge well.
mod_nonspatial_beta <- 
  brm(data = df, family = Beta(),
      Stability ~ 1 + Landuse + (1+Landuse|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666)
## Compiling Stan program...
## Trying to compile a simple C file
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
## Start sampling
## Warning: There were 1269 divergent transitions after warmup. See
## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
## to find out why this is a problem and how to eliminate them.
## Warning: Examine the pairs() plot to diagnose sampling problems
mod_nonspatial_beta <- add_criterion(mod_nonspatial_beta, "loo")
## Warning: Found 19 observations with a pareto_k > 0.7 in model
## 'mod_nonspatial_beta'. It is recommended to set 'moment_match = TRUE' in order
## to perform moment matching for problematic observations.
#check MCMC traces
mcmc_plot(mod_nonspatial_beta, type = "trace") + theme_cowplot()

#check for agreement of chains
mcmc_plot(mod_nonspatial_beta, type = "dens_overlay") + theme_cowplot()

# plot posterior estimates of fixed effects
mcmc_plot(mod_nonspatial_beta, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

## no effects ##
## Parameter fits and stats 
mod_nonspatial_beta$fit # Rhat values closer to 1 and n_eff values > 1000 are ideal.
## Inference for Stan model: 92ef50f012c07027fd18c0f0569e8673.
## 4 chains, each with iter=50000; warmup=5000; thin=2; 
## post-warmup draws per chain=22500, total post-warmup draws=90000.
## 
##                                            mean se_mean    sd   2.5%    25%
## b_Intercept                                0.04    0.00  0.53  -1.01  -0.30
## b_LanduseDeveloped                         1.11    0.00  0.64  -0.15   0.70
## sd_Site_ID__Intercept                      1.77    0.00  0.42   1.08   1.48
## sd_Site_ID__LanduseDeveloped               1.56    0.01  0.66   0.20   1.15
## cor_Site_ID__Intercept__LanduseDeveloped  -0.86    0.00  0.28  -1.00  -0.99
## phi                                       31.22    0.57 29.32   4.90  12.94
## r_Site_ID[CHATANOP,Intercept]              0.52    0.00  0.69  -0.84   0.07
## r_Site_ID[GESASHIOP,Intercept]             0.83    0.00  0.70  -0.55   0.37
## r_Site_ID[HEIWAOP,Intercept]               1.26    0.00  0.73  -0.15   0.78
## r_Site_ID[HENTONAOP,Intercept]            -0.07    0.01  1.60  -3.30  -1.03
## r_Site_ID[KATSUUDAKEFR,Intercept]         -0.16    0.01  1.61  -3.42  -1.15
## r_Site_ID[KEMINFR,Intercept]               0.14    0.01  1.60  -3.15  -0.82
## r_Site_ID[KURASHIKIOP,Intercept]          -1.23    0.00  0.72  -2.70  -1.68
## r_Site_ID[MANABIFR,Intercept]             -0.37    0.02  1.77  -3.94  -1.45
## r_Site_ID[NAGOFR,Intercept]                0.10    0.00  0.68  -1.24  -0.34
## r_Site_ID[NAKAGUSUKUFR,Intercept]         -1.12    0.00  0.72  -2.57  -1.57
## r_Site_ID[OISTFR,Intercept]                0.07    0.01  1.62  -3.23  -0.90
## r_Site_ID[OISTOP,Intercept]                0.14    0.01  1.59  -3.11  -0.83
## r_Site_ID[OKUFR,Intercept]                 0.16    0.02  1.63  -3.11  -0.83
## r_Site_ID[OYAMAOP,Intercept]              -0.26    0.00  0.69  -1.63  -0.70
## r_Site_ID[SEFAFR,Intercept]                1.26    0.00  0.73  -0.17   0.78
## r_Site_ID[SENBARUOP,Intercept]             0.85    0.00  0.71  -0.55   0.40
## r_Site_ID[SUEYOSHIFR,Intercept]            0.60    0.00  0.70  -0.78   0.15
## r_Site_ID[TAMAGUSUKUFR,Intercept]         -5.14    0.01  1.13  -7.45  -5.88
## r_Site_ID[TOUNANOP,Intercept]              1.26    0.00  0.74  -0.17   0.78
## r_Site_ID[UEHARAFR,Intercept]              1.26    0.00  0.73  -0.17   0.78
## r_Site_ID[YONAFR,Intercept]                0.13    0.01  1.60  -3.18  -0.84
## r_Site_ID[CHATANOP,LanduseDeveloped]      -0.41    0.01  0.83  -2.17  -0.89
## r_Site_ID[GESASHIOP,LanduseDeveloped]     -0.67    0.01  0.86  -2.47  -1.19
## r_Site_ID[HEIWAOP,LanduseDeveloped]       -1.02    0.01  0.94  -2.98  -1.60
## r_Site_ID[HENTONAOP,LanduseDeveloped]      0.00    0.01  1.55  -3.22  -0.86
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]  -0.01    0.01  1.56  -3.38  -0.86
## r_Site_ID[KEMINFR,LanduseDeveloped]        0.02    0.01  1.56  -3.12  -0.86
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]    0.99    0.01  0.94  -0.68   0.36
## r_Site_ID[MANABIFR,LanduseDeveloped]      -0.05    0.02  1.72  -3.80  -0.96
## r_Site_ID[NAGOFR,LanduseDeveloped]        -0.08    0.01  0.80  -1.72  -0.53
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]   0.90    0.01  0.91  -0.75   0.29
## r_Site_ID[OISTFR,LanduseDeveloped]         0.02    0.01  1.57  -3.19  -0.84
## r_Site_ID[OISTOP,LanduseDeveloped]         0.01    0.01  1.54  -3.10  -0.86
## r_Site_ID[OKUFR,LanduseDeveloped]         -0.01    0.02  1.58  -3.29  -0.88
## r_Site_ID[OYAMAOP,LanduseDeveloped]        0.21    0.00  0.81  -1.39  -0.25
## r_Site_ID[SEFAFR,LanduseDeveloped]        -1.01    0.01  0.94  -2.96  -1.59
## r_Site_ID[SENBARUOP,LanduseDeveloped]     -0.68    0.01  0.87  -2.52  -1.20
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]    -0.48    0.01  0.84  -2.26  -0.97
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]   4.15    0.02  2.11  -0.14   2.87
## r_Site_ID[TOUNANOP,LanduseDeveloped]      -1.02    0.01  0.94  -2.98  -1.60
## r_Site_ID[UEHARAFR,LanduseDeveloped]      -1.01    0.01  0.94  -2.98  -1.58
## r_Site_ID[YONAFR,LanduseDeveloped]         0.02    0.01  1.56  -3.13  -0.85
## lprior                                   -13.73    0.02  1.20 -16.44 -14.44
## lp__                                     -35.21    0.10  9.01 -52.95 -41.25
##                                             50%    75%  97.5% n_eff Rhat
## b_Intercept                                0.04   0.37   1.07 14888    1
## b_LanduseDeveloped                         1.11   1.52   2.40 17031    1
## sd_Site_ID__Intercept                      1.73   2.02   2.72 13184    1
## sd_Site_ID__LanduseDeveloped               1.58   1.99   2.85 17236    1
## cor_Site_ID__Intercept__LanduseDeveloped  -0.96  -0.88   0.13 35616    1
## phi                                       22.15  38.48 115.31  2679    1
## r_Site_ID[CHATANOP,Intercept]              0.52   0.96   1.91 22534    1
## r_Site_ID[GESASHIOP,Intercept]             0.83   1.28   2.25 23546    1
## r_Site_ID[HEIWAOP,Intercept]               1.25   1.73   2.74 23841    1
## r_Site_ID[HENTONAOP,Intercept]            -0.06   0.90   3.15 15231    1
## r_Site_ID[KATSUUDAKEFR,Intercept]         -0.18   0.82   3.17 22707    1
## r_Site_ID[KEMINFR,Intercept]               0.14   1.12   3.35 24130    1
## r_Site_ID[KURASHIKIOP,Intercept]          -1.22  -0.76   0.18 25635    1
## r_Site_ID[MANABIFR,Intercept]             -0.41   0.69   3.28 11753    1
## r_Site_ID[NAGOFR,Intercept]                0.10   0.53   1.45 23936    1
## r_Site_ID[NAKAGUSUKUFR,Intercept]         -1.11  -0.66   0.27 23677    1
## r_Site_ID[OISTFR,Intercept]                0.07   1.03   3.33 11889    1
## r_Site_ID[OISTOP,Intercept]                0.15   1.12   3.34 26850    1
## r_Site_ID[OKUFR,Intercept]                 0.15   1.14   3.53 10302    1
## r_Site_ID[OYAMAOP,Intercept]              -0.25   0.18   1.10 23926    1
## r_Site_ID[SEFAFR,Intercept]                1.25   1.73   2.73 22160    1
## r_Site_ID[SENBARUOP,Intercept]             0.85   1.30   2.28 22880    1
## r_Site_ID[SUEYOSHIFR,Intercept]            0.60   1.04   1.99 24233    1
## r_Site_ID[TAMAGUSUKUFR,Intercept]         -5.11  -4.37  -3.01  9882    1
## r_Site_ID[TOUNANOP,Intercept]              1.25   1.73   2.73 23241    1
## r_Site_ID[UEHARAFR,Intercept]              1.25   1.73   2.74 25088    1
## r_Site_ID[YONAFR,Intercept]                0.14   1.11   3.37 19028    1
## r_Site_ID[CHATANOP,LanduseDeveloped]      -0.36   0.07   1.18 25237    1
## r_Site_ID[GESASHIOP,LanduseDeveloped]     -0.62  -0.10   0.94 25750    1
## r_Site_ID[HEIWAOP,LanduseDeveloped]       -0.98  -0.38   0.66 23565    1
## r_Site_ID[HENTONAOP,LanduseDeveloped]      0.00   0.85   3.24 14271    1
## r_Site_ID[KATSUUDAKEFR,LanduseDeveloped]   0.02   0.87   3.15 21848    1
## r_Site_ID[KEMINFR,LanduseDeveloped]       -0.01   0.85   3.36 22039    1
## r_Site_ID[KURASHIKIOP,LanduseDeveloped]    0.94   1.55   2.96 24185    1
## r_Site_ID[MANABIFR,LanduseDeveloped]       0.02   0.93   3.36 11061    1
## r_Site_ID[NAGOFR,LanduseDeveloped]        -0.06   0.37   1.52 24784    1
## r_Site_ID[NAKAGUSUKUFR,LanduseDeveloped]   0.86   1.44   2.80 31509    1
## r_Site_ID[OISTFR,LanduseDeveloped]         0.00   0.85   3.34 11750    1
## r_Site_ID[OISTOP,LanduseDeveloped]        -0.02   0.84   3.30 23740    1
## r_Site_ID[OKUFR,LanduseDeveloped]         -0.02   0.85   3.29 10179    1
## r_Site_ID[OYAMAOP,LanduseDeveloped]        0.17   0.67   1.88 28569    1
## r_Site_ID[SEFAFR,LanduseDeveloped]        -0.97  -0.37   0.66 23434    1
## r_Site_ID[SENBARUOP,LanduseDeveloped]     -0.64  -0.11   0.93 23163    1
## r_Site_ID[SUEYOSHIFR,LanduseDeveloped]    -0.43   0.02   1.12 23027    1
## r_Site_ID[TAMAGUSUKUFR,LanduseDeveloped]   4.34   5.57   7.97 16437    1
## r_Site_ID[TOUNANOP,LanduseDeveloped]      -0.98  -0.38   0.68 25148    1
## r_Site_ID[UEHARAFR,LanduseDeveloped]      -0.97  -0.38   0.68 27877    1
## r_Site_ID[YONAFR,LanduseDeveloped]        -0.01   0.86   3.39 18193    1
## lprior                                   -13.62 -12.90 -11.67  4691    1
## lp__                                     -35.21 -29.13 -17.65  7718    1
## 
## Samples were drawn using NUTS(diag_e) at Mon Nov 14 13:49:42 2022.
## For each parameter, n_eff is a crude measure of effective sample size,
## and Rhat is the potential scale reduction factor on split chains (at 
## convergence, Rhat=1).
bayes_R2(mod_nonspatial_beta) # pseudo r-squared of model
##     Estimate  Est.Error      Q2.5     Q97.5
## R2 0.8693717 0.08974146 0.6334231 0.9772584
# simulate data from 500 random draws of posterior and compare it to observed data
# the black line should run through the center of the blue lines
pp_check(mod_nonspatial_beta, ndraws = 500) + theme_cowplot()

## Spatial Autocorrelation test
bres <- residuals(mod_nonspatial_beta)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T)) # make distance matrix 
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
Moran.I(bres, d_mat_inv) # non-significant = no spatial autocorrelation
## $observed
## [1] -0.1478582
## 
## $expected
## [1] -0.05
## 
## $sd
## [1] 0.09678781
## 
## $p.value
## [1] 0.3119882

acoustic index spatial variability

Not using same Bayesian models for spatial variability here. Instead, using break-point models to see if spatial variability changes after typhoons, and whether values and value change differ by land use. NB: set break-points manually before and after typhoons, as this is a priori expectation for break point locations (then compare model performance against linear model without breaks).

NDSI - typhoon x landuse interaction

# prepare data
df<-tidy.spatial_AI %>%
  filter(Index %in% "NDSI" & response_group %in% 'Total_var') # get pre vs post data for comparison
df2<-df
df2$Date_Time<-df2$Date_Time %>%  julian.Date() %>% as.numeric() # convert to numeric date format for model
df2$Date_Time<-df2$Date_Time - min(df2$Date_Time) # scale date to start at zero for model

#hist(df$Stability) # looks Gaussian
olm<-lm(Stability ~ 0 + Date_Time,data = df2) # linear model
summary(olm)
## 
## Call:
## lm(formula = Stability ~ 0 + Date_Time, data = df2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.12071 -0.01316  0.02577  0.09152  0.17317 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## Date_Time 5.993e-08  4.278e-10   140.1   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.07568 on 3071 degrees of freedom
## Multiple R-squared:  0.8647, Adjusted R-squared:  0.8646 
## F-statistic: 1.962e+04 on 1 and 3071 DF,  p-value: < 2.2e-16
#plot(olm)

## break-point model ##
os <- segmented(olm, 
                seg.Z = ~ Date_Time, # which variables to break
                psi = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric()), # break after typhoons
                control = seg.control(it.max = 0)) # it.max = 0 prevents bootstrap procedure (i.e. forces manual break-point)

AIC(os,olm) # break point model performs better
##     df       AIC
## os   4 -8353.921
## olm  2 -7138.036
## davies test of the change in slope after break points
davies.test(olm,values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # break after typhoons
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Date_Time ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = Date_Time
## 'best' at = 2462400, n.points = 2, p-value < 2.2e-16
## alternative hypothesis: two.sided
summary(os)
## 
## Call:
## lm(formula = Stability ~ Date_Time + U1.Date_Time + U2.Date_Time - 
##     1, data = mfExt)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.091947 -0.014738  0.006873  0.048888  0.172848 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## Date_Time     9.592e-08  1.064e-09   90.13   <2e-16 ***
## U1.Date_Time -1.617e-07  7.642e-09  -21.16   <2e-16 ***
## U2.Date_Time  9.797e-08  8.397e-09   11.67   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.06207 on 3069 degrees of freedom
## Multiple R-squared:  0.909,  Adjusted R-squared:  0.9089 
## F-statistic: 1.022e+04 on 3 and 3069 DF,  p-value: < 2.2e-16
# get dates of manual breakpoint
Psi_1<-df$Date_Time[df$Period %in% 'Trami'][1]
Psi_2<-df$Date_Time[df$Period %in% 'Post-typhoon'][1]

# compare pre- and post-break acoustic index values
Break_results<-df %>% 
  filter(Period %in% c('Pre-typhoon','Post-typhoon')) %>% 
  group_by(Period) %>% 
  summarise(Med=median(Stability),
            Lo_95=quantile(Stability,probs = 0.05),
            Up_95=quantile(Stability,probs = 0.95))
Break_results$Period<-Break_results$Period %>% as.character() %>% parse_factor(levels = c('Pre-typhoon','Post-typhoon'))

Plot results:

plot1<-df %>% ggplot(aes(x = Date_Time,
                  y = Stability)) +
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Trami'][1],lty = 2) + 
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Post-typhoon'][1],lty = 2) + 
  geom_line(show.legend = F) + 
  labs(x = "Time",
       y = "NDSI spatial variability") + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max())) 

plot2<-Break_results %>% ggplot(aes(x = Period,
                  y = Med,
                  ymin = Lo_95,
                  ymax = Up_95,
                  shape = Period)) +
  geom_pointrange(fatten = 5,
                  show.legend = F) + 
  labs(x = "Time period",
       y = element_blank()) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max()))

panel_a<-plot1 + plot2 + plot_layout(widths = c(3,1))
panel_a

Now check for landuse effect:

# prepare data
df<-tidy.spatial_AI %>%
  filter(Index %in% "NDSI" & response_group %in% c('Forest_Var','Developed_Var')) # get pre vs post data for comparison
df$response_group[df$response_group %in% 'Forest_Var']<-'Forest'
df$response_group[df$response_group %in% 'Developed_Var']<-'Developed'
colnames(df)[4]<-'Landuse'
df$Landuse<-df$Landuse %>% as.character() %>% parse_factor(levels = c('Forest','Developed')) # change levels for model
df2<-df
df2$Date_Time<-df2$Date_Time %>%  julian.Date() %>% as.numeric() # convert to numeric date format for model
df2$Date_Time<-df2$Date_Time - min(df2$Date_Time) # scale date to start at zero for model

# split out time series for each land use class separately
temp<-model.matrix(~ 0 + df2$Landuse)*df2$Date_Time
date_for<-temp[,1]
date_dev<-temp[,2]
rm(temp)

#hist(df$Stability) # looks Gaussian
olm<-lm(Stability ~ 0 + Landuse + date_for + date_dev,data = df2) # linear model

## break-point model ##
os <- segmented(olm, 
                seg.Z = ~ date_for + date_dev, # which variables to break
                psi = list(date_for=c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric()), # break after typhoons
                  date_dev=c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())), # break after typhoons
                control = seg.control(it.max = 0)) # it.max = 0 prevents bootstrap procedure (i.e. forces manual break-point)

AIC(os,olm) # break point model performs better
##     df       AIC
## os   9 -25599.50
## olm  5 -24645.79
## davies test of the change in slope after break points
davies.test(olm,seg.Z = ~ date_for,
            values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(),
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # test for change in slope of forest sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Landuse + date_for + date_dev ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = date_for
## 'best' at = 2462400, n.points = 2, p-value < 2.2e-16
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_dev,
            values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(),
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # test for change in slope of developed sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Landuse + date_for + date_dev ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = date_dev
## 'best' at = 2462400, n.points = 2, p-value < 2.2e-16
## alternative hypothesis: two.sided
summary(os)
## 
## Call:
## lm(formula = Stability ~ Landuse + date_for + date_dev + U1.date_for + 
##     U2.date_for + U1.date_dev + U2.date_dev - 1, data = mfExt)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.092178 -0.017600  0.000435  0.016101  0.129808 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## LanduseForest     2.017e-01  1.578e-03 127.787  < 2e-16 ***
## LanduseDeveloped  1.142e-01  1.578e-03  72.375  < 2e-16 ***
## date_for         -7.566e-10  1.039e-09  -0.728 0.466372    
## date_dev         -5.820e-10  1.039e-09  -0.560 0.575302    
## U1.date_for       5.013e-08  4.256e-09  11.778  < 2e-16 ***
## U2.date_for      -1.493e-08  4.257e-09  -3.506 0.000458 ***
## U1.date_dev       1.757e-08  4.256e-09   4.129  3.7e-05 ***
## U2.date_dev       8.740e-09  4.257e-09   2.053 0.040115 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.03011 on 6136 degrees of freedom
## Multiple R-squared:  0.9762, Adjusted R-squared:  0.9762 
## F-statistic: 3.148e+04 on 8 and 6136 DF,  p-value: < 2.2e-16
# get dates of manual breakpoint
Psi_1<-df$Date_Time[df$Period %in% 'Trami'][1]
Psi_2<-df$Date_Time[df$Period %in% 'Post-typhoon'][1]

# compare pre- and post-break acoustic index values
Break_results<-df %>% 
  filter(Period %in% c('Pre-typhoon','Post-typhoon')) %>% 
  group_by(Landuse,Period) %>% 
  summarise(Med=median(Stability),
            Lo_95=quantile(Stability,probs = 0.05),
            Up_95=quantile(Stability,probs = 0.95))
## `summarise()` has grouped output by 'Landuse'. You can override using the
## `.groups` argument.
Break_results$Period<-Break_results$Period %>% as.character() %>% parse_factor(levels = c('Pre-typhoon','Post-typhoon'))
Break_results$Landuse<-Break_results$Landuse %>% as.character() %>% parse_factor(levels = c('Forest','Developed'))

Plot results:

plot1<-df %>% ggplot(aes(x = Date_Time,
                  y = Stability,
                  col = Landuse)) +
  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Trami'][1],lty = 2) + 
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Post-typhoon'][1],lty = 2) + 
  geom_line(show.legend = F) + 
  labs(x = "Time",
       y = "NDSI spatial variability") + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max())) 

plot2<-Break_results %>% ggplot(aes(x = Landuse,
                  y = Med,
                  ymin = Lo_95,
                  ymax = Up_95,
                  col = Landuse,
                  shape = Period)) +
  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  geom_pointrange(position = position_jitterdodge(),
                  fatten = 5,
                  show.legend = F) + 
  labs(x = "Landuse",
       y = element_blank()) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max()))

panel_b<-plot1 + plot2 + plot_layout(widths = c(3,1))
panel_b

panel_a / panel_b

For axis legend: “dashed lines delineate the pre- and post-typhoon periods.”

NDSI_Bio - Landuse x typhoon effect

# prepare data
df<-tidy.spatial_AI %>%
  filter(Index %in% "NDSI_Bio" & response_group %in% 'Total_var') # get pre vs post data for comparison
df2<-df
df2$Date_Time<-df2$Date_Time %>%  julian.Date() %>% as.numeric() # convert to numeric date format for model
df2$Date_Time<-df2$Date_Time - min(df2$Date_Time) # scale date to start at zero for model

#hist(df$Stability) # looks Gaussian
olm<-lm(Stability ~ 0 + Date_Time,data = df2) # linear model
summary(olm)
## 
## Call:
## lm(formula = Stability ~ 0 + Date_Time, data = df2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.15411 -0.01222  0.02325  0.09981  0.17069 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## Date_Time 7.834e-08  4.439e-10   176.5   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.07853 on 3071 degrees of freedom
## Multiple R-squared:  0.9103, Adjusted R-squared:  0.9102 
## F-statistic: 3.115e+04 on 1 and 3071 DF,  p-value: < 2.2e-16
#plot(olm)

## break-point model ##
os <- segmented(olm, 
                seg.Z = ~ Date_Time, # which variables to break
                psi = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric()), # break after typhoons
                control = seg.control(it.max = 0)) # it.max = 0 prevents bootstrap procedure (i.e. forces manual break-point)

AIC(os,olm) # break point model performs better
##     df       AIC
## os   4 -7938.108
## olm  2 -6911.230
## davies test of the change in slope after break points
davies.test(olm,values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # break after typhoons
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Date_Time ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = Date_Time
## 'best' at = 2462400, n.points = 2, p-value < 2.2e-16
## alternative hypothesis: two.sided
summary(os)
## 
## Call:
## lm(formula = Stability ~ Date_Time + U1.Date_Time + U2.Date_Time - 
##     1, data = mfExt)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.099923 -0.019365  0.008329  0.063828  0.169459 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## Date_Time     1.126e-07  1.139e-09  98.902   <2e-16 ***
## U1.Date_Time -1.474e-07  8.177e-09 -18.025   <2e-16 ***
## U2.Date_Time  8.354e-08  8.985e-09   9.298   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.06642 on 3069 degrees of freedom
## Multiple R-squared:  0.9358, Adjusted R-squared:  0.9358 
## F-statistic: 1.492e+04 on 3 and 3069 DF,  p-value: < 2.2e-16
# get dates of manual breakpoint
Psi_1<-df$Date_Time[df$Period %in% 'Trami'][1]
Psi_2<-df$Date_Time[df$Period %in% 'Post-typhoon'][1]

# compare pre- and post-break acoustic index values
Break_results<-df %>% 
  filter(Period %in% c('Pre-typhoon','Post-typhoon')) %>% 
  group_by(Period) %>% 
  summarise(Med=median(Stability),
            Lo_95=quantile(Stability,probs = 0.05),
            Up_95=quantile(Stability,probs = 0.95))
Break_results$Period<-Break_results$Period %>% as.character() %>% parse_factor(levels = c('Pre-typhoon','Post-typhoon'))

Plot results:

plot1<-df %>% ggplot(aes(x = Date_Time,
                  y = Stability)) +
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Trami'][1],lty = 2) + 
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Post-typhoon'][1],lty = 2) + 
  geom_line(show.legend = F) + 
  labs(x = "Time",
       y = expression(paste("NDSI"["Bio"]," spatial variability"))) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max())) 

plot2<-Break_results %>% ggplot(aes(x = Period,
                  y = Med,
                  ymin = Lo_95,
                  ymax = Up_95,
                  shape = Period)) +
  geom_pointrange(fatten = 5,
                  show.legend = F) + 
  labs(x = "Time period",
       y = element_blank()) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max()))

panel_a<-plot1 + plot2 + plot_layout(widths = c(3,1))
panel_a

Now check for landuse effect:

# prepare data
df<-tidy.spatial_AI %>%
  filter(Index %in% "NDSI_Bio" & response_group %in% c('Forest_Var','Developed_Var')) # get pre vs post data for comparison
df$response_group[df$response_group %in% 'Forest_Var']<-'Forest'
df$response_group[df$response_group %in% 'Developed_Var']<-'Developed'
colnames(df)[4]<-'Landuse'
df$Landuse<-df$Landuse %>% as.character() %>% parse_factor(levels = c('Forest','Developed')) # change levels for model
df2<-df
df2$Date_Time<-df2$Date_Time %>%  julian.Date() %>% as.numeric() # convert to numeric date format for model
df2$Date_Time<-df2$Date_Time - min(df2$Date_Time) # scale date to start at zero for model

# split out time series for each land use class separately
temp<-model.matrix(~ 0 + df2$Landuse)*df2$Date_Time
date_for<-temp[,1]
date_dev<-temp[,2]
rm(temp)

#hist(df$Stability) # looks Gaussian
olm<-lm(Stability ~ 0 + Landuse + date_for + date_dev,data = df2) # linear model

## break-point model ##
os <- segmented(olm, 
                seg.Z = ~ date_for + date_dev, # which variables to break
                psi = list(date_for=c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric()), # break after typhoons
                  date_dev=c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())), # break after typhoons
                control = seg.control(it.max = 0)) # it.max = 0 prevents bootstrap procedure (i.e. forces manual break-point)

AIC(os,olm) # break point model performs better
##     df       AIC
## os   9 -23923.69
## olm  5 -22706.95
## davies test of the change in slope after break points
davies.test(olm,seg.Z = ~ date_for,
            values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(),
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # test for change in slope of forest sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Landuse + date_for + date_dev ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = date_for
## 'best' at = 2462400, n.points = 2, p-value < 2.2e-16
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_dev,
            values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(),
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # test for change in slope of developed sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Landuse + date_for + date_dev ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = date_dev
## 'best' at = 2462400, n.points = 2, p-value < 2.2e-16
## alternative hypothesis: two.sided
summary(os)
## 
## Call:
## lm(formula = Stability ~ Landuse + date_for + date_dev + U1.date_for + 
##     U2.date_for + U1.date_dev + U2.date_dev - 1, data = mfExt)
## 
## Residuals:
##       Min        1Q    Median        3Q       Max 
## -0.121497 -0.022101  0.003447  0.022288  0.115851 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## LanduseForest     2.264e-01  1.809e-03 125.181  < 2e-16 ***
## LanduseDeveloped  9.354e-02  1.809e-03  51.713  < 2e-16 ***
## date_for          5.256e-09  1.190e-09   4.415 1.03e-05 ***
## date_dev          2.152e-08  1.190e-09  18.076  < 2e-16 ***
## U1.date_for       8.529e-08  4.878e-09  17.486  < 2e-16 ***
## U2.date_for      -3.719e-08  4.879e-09  -7.622 2.88e-14 ***
## U1.date_dev       8.107e-08  4.878e-09  16.620  < 2e-16 ***
## U2.date_dev      -6.912e-08  4.879e-09 -14.167  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.0345 on 6136 degrees of freedom
## Multiple R-squared:  0.9818, Adjusted R-squared:  0.9818 
## F-statistic: 4.138e+04 on 8 and 6136 DF,  p-value: < 2.2e-16
# get dates of manual breakpoint
Psi_1<-df$Date_Time[df$Period %in% 'Trami'][1]
Psi_2<-df$Date_Time[df$Period %in% 'Post-typhoon'][1]

# compare pre- and post-break acoustic index values
Break_results<-df %>% 
  filter(Period %in% c('Pre-typhoon','Post-typhoon')) %>% 
  group_by(Landuse,Period) %>% 
  summarise(Med=median(Stability),
            Lo_95=quantile(Stability,probs = 0.05),
            Up_95=quantile(Stability,probs = 0.95))
## `summarise()` has grouped output by 'Landuse'. You can override using the
## `.groups` argument.
Break_results$Period<-Break_results$Period %>% as.character() %>% parse_factor(levels = c('Pre-typhoon','Post-typhoon'))
Break_results$Landuse<-Break_results$Landuse %>% as.character() %>% parse_factor(levels = c('Forest','Developed'))

Plot results:

plot1<-df %>% ggplot(aes(x = Date_Time,
                  y = Stability,
                  col = Landuse)) +
  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Trami'][1],lty = 2) + 
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Post-typhoon'][1],lty = 2) + 
  geom_line(show.legend = F) + 
  labs(x = "Time",
       y = expression(paste("NDSI"["Bio"]," spatial variability"))) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max())) 

plot2<-Break_results %>% ggplot(aes(x = Landuse,
                  y = Med,
                  ymin = Lo_95,
                  ymax = Up_95,
                  col = Landuse,
                  shape = Period)) +
  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  geom_pointrange(position = position_jitterdodge(),
                  fatten = 5,
                  show.legend = F) + 
  labs(x = "Landuse",
       y = element_blank()) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max()))

panel_b<-plot1 + plot2 + plot_layout(widths = c(3,1))
panel_b

panel_a / panel_b

NDSI_Anthro - no effect

# prepare data
df<-tidy.spatial_AI %>%
  filter(Index %in% "NDSI_Anth" & response_group %in% 'Total_var') # get pre vs post data for comparison
df2<-df
df2$Date_Time<-df2$Date_Time %>%  julian.Date() %>% as.numeric() # convert to numeric date format for model
df2$Date_Time<-df2$Date_Time - min(df2$Date_Time) # scale date to start at zero for model

#hist(df$Stability) # looks Gaussian
olm<-lm(Stability ~ 0 + Date_Time,data = df2) # linear model
summary(olm)
## 
## Call:
## lm(formula = Stability ~ 0 + Date_Time, data = df2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.41002 -0.09525  0.10893  0.46349  0.68911 
## 
## Coefficients:
##            Estimate Std. Error t value Pr(>|t|)    
## Date_Time 1.323e-07  2.081e-09   63.59   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3681 on 3071 degrees of freedom
## Multiple R-squared:  0.5684, Adjusted R-squared:  0.5682 
## F-statistic:  4044 on 1 and 3071 DF,  p-value: < 2.2e-16
#plot(olm)

## break-point model ##
os <- segmented(olm, 
                seg.Z = ~ Date_Time, # which variables to break
                psi = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric()), # break after typhoons
                control = seg.control(it.max = 0)) # it.max = 0 prevents bootstrap procedure (i.e. forces manual break-point)

AIC(os,olm) # break point model performs better
##     df       AIC
## os   4  848.6697
## olm  2 2580.0874
## davies test of the change in slope after break points
davies.test(olm,values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # break after typhoons
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Date_Time ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = Date_Time
## 'best' at = 2462400, n.points = 2, p-value < 2.2e-16
## alternative hypothesis: two.sided
summary(os)
## 
## Call:
## lm(formula = Stability ~ Date_Time + U1.Date_Time + U2.Date_Time - 
##     1, data = mfExt)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.61843 -0.07874  0.07295  0.30630  0.57547 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## Date_Time     3.278e-07  4.759e-09   68.89   <2e-16 ***
## U1.Date_Time -8.166e-07  3.417e-08  -23.90   <2e-16 ***
## U2.Date_Time  4.407e-07  3.755e-08   11.73   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2776 on 3069 degrees of freedom
## Multiple R-squared:  0.7547, Adjusted R-squared:  0.7544 
## F-statistic:  3147 on 3 and 3069 DF,  p-value: < 2.2e-16
# get dates of manual breakpoint
Psi_1<-df$Date_Time[df$Period %in% 'Trami'][1]
Psi_2<-df$Date_Time[df$Period %in% 'Post-typhoon'][1]

# compare pre- and post-break acoustic index values
Break_results<-df %>% 
  filter(Period %in% c('Pre-typhoon','Post-typhoon')) %>% 
  group_by(Period) %>% 
  summarise(Med=median(Stability),
            Lo_95=quantile(Stability,probs = 0.05),
            Up_95=quantile(Stability,probs = 0.95))
Break_results$Period<-Break_results$Period %>% as.character() %>% parse_factor(levels = c('Pre-typhoon','Post-typhoon'))

Plot results:

plot1<-df %>% ggplot(aes(x = Date_Time,
                  y = Stability)) +
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Trami'][1],lty = 2) + 
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Post-typhoon'][1],lty = 2) + 
  geom_line(show.legend = F) + 
  labs(x = "Time",
       y = expression(paste("NDSI"["Anthro"]," spatial variability"))) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max())) 

plot2<-Break_results %>% ggplot(aes(x = Period,
                  y = Med,
                  ymin = Lo_95,
                  ymax = Up_95,
                  shape = Period)) +
  geom_pointrange(fatten = 5,
                  show.legend = F) + 
  labs(x = "Time period",
       y = element_blank()) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max()))

panel_a<-plot1 + plot2 + plot_layout(widths = c(3,1))
panel_a

NB: model slopes differ slightly so Davies test is sig.

Now check for landuse effect:

# prepare data
df<-tidy.spatial_AI %>%
  filter(Index %in% "NDSI_Anth" & response_group %in% c('Forest_Var','Developed_Var')) # get pre vs post data for comparison
df$response_group[df$response_group %in% 'Forest_Var']<-'Forest'
df$response_group[df$response_group %in% 'Developed_Var']<-'Developed'
colnames(df)[4]<-'Landuse'
df$Landuse<-df$Landuse %>% as.character() %>% parse_factor(levels = c('Forest','Developed')) # change levels for model
df2<-df
df2$Date_Time<-df2$Date_Time %>%  julian.Date() %>% as.numeric() # convert to numeric date format for model
df2$Date_Time<-df2$Date_Time - min(df2$Date_Time) # scale date to start at zero for model

# split out time series for each land use class separately
temp<-model.matrix(~ 0 + df2$Landuse)*df2$Date_Time
date_for<-temp[,1]
date_dev<-temp[,2]
rm(temp)

#hist(df$Stability) # looks Gaussian
olm<-lm(Stability ~ 0 + Landuse + date_for + date_dev,data = df2) # linear model

## break-point model ##
os <- segmented(olm, 
                seg.Z = ~ date_for + date_dev, # which variables to break
                psi = list(date_for=c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric()), # break after typhoons
                  date_dev=c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(), # break at Trami
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())), # break after typhoons
                control = seg.control(it.max = 0)) # it.max = 0 prevents bootstrap procedure (i.e. forces manual break-point)

AIC(os,olm) # break point model performs better
##     df       AIC
## os   9 -5845.419
## olm  5 -5696.789
## davies test of the change in slope after break points
davies.test(olm,seg.Z = ~ date_for,
            values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(),
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # test for change in slope of forest sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Landuse + date_for + date_dev ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = date_for
## 'best' at = 2462400, n.points = 2, p-value = 1.274e-08
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_dev,
            values = c(df$Date_Time[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric(),
                  df$Date_Time[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - 
                  df$Date_Time[1] %>% julian.Date() %>% as.numeric())) # test for change in slope of developed sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Landuse + date_for + date_dev ,   method = lm 
## model = gaussian , link = identity  
## segmented variable = date_dev
## 'best' at = 2462400, n.points = 2, p-value < 2.2e-16
## alternative hypothesis: two.sided
summary(os)
## 
## Call:
## lm(formula = Stability ~ Landuse + date_for + date_dev + U1.date_for + 
##     U2.date_for + U1.date_dev + U2.date_dev - 1, data = mfExt)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.3870 -0.1040 -0.0239  0.1164  0.3847 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## LanduseForest     5.857e-01  7.877e-03  74.363  < 2e-16 ***
## LanduseDeveloped  6.909e-01  7.877e-03  87.714  < 2e-16 ***
## date_for         -6.227e-09  5.184e-09  -1.201 0.229741    
## date_dev         -1.004e-07  5.184e-09 -19.366  < 2e-16 ***
## U1.date_for      -1.177e-07  2.124e-08  -5.542 3.11e-08 ***
## U2.date_for       8.035e-08  2.125e-08   3.782 0.000157 ***
## U1.date_dev       7.223e-08  2.124e-08   3.400 0.000677 ***
## U2.date_dev      -4.929e-10  2.125e-08  -0.023 0.981492    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1503 on 6136 degrees of freedom
## Multiple R-squared:  0.9176, Adjusted R-squared:  0.9175 
## F-statistic:  8540 on 8 and 6136 DF,  p-value: < 2.2e-16
# get dates of manual breakpoint
Psi_1<-df$Date_Time[df$Period %in% 'Trami'][1]
Psi_2<-df$Date_Time[df$Period %in% 'Post-typhoon'][1]

# compare pre- and post-break acoustic index values
Break_results<-df %>% 
  filter(Period %in% c('Pre-typhoon','Post-typhoon')) %>% 
  group_by(Landuse,Period) %>% 
  summarise(Med=median(Stability),
            Lo_95=quantile(Stability,probs = 0.05),
            Up_95=quantile(Stability,probs = 0.95))
## `summarise()` has grouped output by 'Landuse'. You can override using the
## `.groups` argument.
Break_results$Period<-Break_results$Period %>% as.character() %>% parse_factor(levels = c('Pre-typhoon','Post-typhoon'))
Break_results$Landuse<-Break_results$Landuse %>% as.character() %>% parse_factor(levels = c('Forest','Developed'))

Plot results:

plot1<-df %>% ggplot(aes(x = Date_Time,
                  y = Stability,
                  col = Landuse)) +
  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Trami'][1],lty = 2) + 
  geom_vline(xintercept = df$Date_Time[df$Period %in% 'Post-typhoon'][1],lty = 2) + 
  geom_line(show.legend = F) + 
  labs(x = "Time",
       y = expression(paste("NDSI"["Anthro"]," spatial variability"))) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max())) 

plot2<-Break_results %>% ggplot(aes(x = Landuse,
                  y = Med,
                  ymin = Lo_95,
                  ymax = Up_95,
                  col = Landuse,
                  shape = Period)) +
  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  geom_pointrange(position = position_jitterdodge(),
                  fatten = 5,
                  show.legend = F) + 
  labs(x = "Landuse",
       y = element_blank()) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max()))

panel_b<-plot1 + plot2 + plot_layout(widths = c(3,1))
panel_b

panel_a / panel_b

NB: model slopes differ slightly so Davies test is sig.

NB: this is very reassuring - that what we’re seeing in the spatial variability results is biotic and independent of background noise. If results weren’t driven by site differences in biotic responses, we’d see them follow closely the overall trend like for Anthropophony.

Bird detections

NB: Bird detections were not made at every site, so the random site effect fills in the missing sites when constructing posterior draws etc. (we simply ignore those results from sites where detections were not observed).

bird detection mean states

Total detections - species x typhoon effect

dat_pre<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.5 & response_variable %in% 'Pre_mean') 
dat_post<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.5 & response_variable %in% 'Post_mean') 
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)

# change levels for model
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))

df$Stability<-df$Stability+1 # try this to run lognormal model (cannot have zero values)

# set weakly informative priors
all_priors<-c(
  set_prior("normal(0, 2)",coef = "LanduseDeveloped"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:TyphoonPost"),
  set_prior("normal(0, 2)",coef = "Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "TyphoonPost"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDOtus_elegans"))

# Fit bayesian mixed effects model
mod_nonspatial_log <- 
  brm(data = df, family = lognormal(),
      round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + # used round() as poisson needs integers
        Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666, prior = all_priors)
## Compiling Stan program...
## Trying to compile a simple C file
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
## Start sampling
brms::mcmc_plot(mod_nonspatial_log, type = "trace") + theme_cowplot()
## No divergences to plot.

#check for agreement of chains
brms::mcmc_plot(mod_nonspatial_log, type = "dens_overlay") + theme_cowplot()

# plot posterior probabilities
brms::mcmc_plot(mod_nonspatial_log, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

pp_check(mod_nonspatial_log, ndraws = 500) + theme_cowplot() +  scale_x_continuous(limits = c(0,50)) # good fit to data
## Warning: Removed 9564 rows containing non-finite values (stat_density).
## Warning: Removed 19 rows containing non-finite values (stat_density).

bayes_R2(mod_nonspatial_log)
##     Estimate Est.Error      Q2.5     Q97.5
## R2 0.4735329 0.0931045 0.2723411 0.6284559
bres <- residuals(mod_nonspatial_log)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T))
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
ape::Moran.I(bres, d_mat_inv)
## $observed
## [1] 0.008690685
## 
## $expected
## [1] -0.01123596
## 
## $sd
## [1] 0.02164809
## 
## $p.value
## [1] 0.3573219
summary(mod_nonspatial_log)
##  Family: lognormal 
##   Links: mu = identity; sigma = identity 
## Formula: round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1 | Site_ID) 
##    Data: df (Number of observations: 90) 
##   Draws: 4 chains, each with iter = 50000; warmup = 5000; thin = 2;
##          total post-warmup draws = 90000
## 
## Group-Level Effects: 
## ~Site_ID (Number of levels: 22) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.69      0.18     0.37     1.09 1.00    42601    55290
## 
## Population-Level Effects: 
##                                             Estimate Est.Error l-95% CI
## Intercept                                       3.57      0.32     2.94
## LanduseDeveloped                                0.25      0.44    -0.62
## TyphoonPost                                    -0.18      0.32    -0.81
## Species_IDHorornis_diphone                     -1.06      0.35    -1.76
## Species_IDOtus_elegans                         -0.46      1.43    -3.25
## LanduseDeveloped:TyphoonPost                   -0.41      0.38    -1.17
## LanduseDeveloped:Species_IDHorornis_diphone    -0.32      0.41    -1.12
## LanduseDeveloped:Species_IDOtus_elegans        -0.47      1.43    -3.26
## TyphoonPost:Species_IDHorornis_diphone         -1.25      0.39    -2.01
## TyphoonPost:Species_IDOtus_elegans             -0.13      0.55    -1.20
##                                             u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                       4.20 1.00    65820    77332
## LanduseDeveloped                                1.12 1.00    60698    75892
## TyphoonPost                                     0.45 1.00    79070    81088
## Species_IDHorornis_diphone                     -0.36 1.00    74815    80432
## Species_IDOtus_elegans                          2.34 1.00    80432    81997
## LanduseDeveloped:TyphoonPost                    0.35 1.00    81738    83245
## LanduseDeveloped:Species_IDHorornis_diphone     0.49 1.00    77284    81097
## LanduseDeveloped:Species_IDOtus_elegans         2.31 1.00    80508    81350
## TyphoonPost:Species_IDHorornis_diphone         -0.49 1.00    76040    80466
## TyphoonPost:Species_IDOtus_elegans              0.95 1.00    78671    80924
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.86      0.08     0.72     1.04 1.00    58350    70632
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Plot main species effect:

# Horornis #
mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_Species_IDHorornis_diphone, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_Species_IDHorornis_diphone + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp) 
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
horornisplot <- mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","navajowhite")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (species effect)",
       y = "") + 
  cowplot::theme_minimal_grid()

# Otus #
mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_Species_IDOtus_elegans, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_Species_IDOtus_elegans + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp)
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
otusplot <-mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","navajowhite")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (species effect)",
       y = "") + 
  cowplot::theme_minimal_grid()

# plots #
plot_grid(horornisplot, otusplot, 
          ncol = 2, align = "hv", 
          labels = c("Horonis", "Otus"))

Plot typhoon x species interaction:

# Corvus #
mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_TyphoonPost, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_TyphoonPost + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp)
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
corvusplot <- mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","skyblue")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (typhoon effect)",
       y = "Site") + 
  cowplot::theme_minimal_grid()

# Horornis #
mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_TyphoonPost, `b_TyphoonPost:Species_IDHorornis_diphone`, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_TyphoonPost + `b_TyphoonPost:Species_IDHorornis_diphone` + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp) 
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
horornisplot <- mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","skyblue")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (typhoon effect)",
       y = "") + 
  cowplot::theme_minimal_grid()

# Otus #
mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_TyphoonPost, `b_TyphoonPost:Species_IDOtus_elegans`, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_TyphoonPost + `b_TyphoonPost:Species_IDOtus_elegans` + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp)
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
otusplot <-mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","skyblue")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (typhoon effect)",
       y = "") + 
  cowplot::theme_minimal_grid()

# plots #
plot_grid(corvusplot, horornisplot, otusplot, 
          ncol = 3, align = "hv", 
          labels = c("Corvus", "Horonis", "Otus"))

bird detection temporal variability

Total detections - typhoon effect

dat_pre<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.5 & response_variable %in% 'Pre_Var') 
dat_post<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.5 & response_variable %in% 'Post_Var') 
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)

# change levels for model
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))

df$Stability<-df$Stability+1 # try this to run lognormal model (cannot have zero values)

# set weakly informative priors
all_priors<-c(
  set_prior("normal(0, 2)",coef = "LanduseDeveloped"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:TyphoonPost"),
  set_prior("normal(0, 2)",coef = "Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "TyphoonPost"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDOtus_elegans"))

# Fit bayesian mixed effects model
mod_nonspatial_log <- 
  brm(data = df, family = lognormal(),
      round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + # used round() as poisson needs integers
        Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1|Site_ID),
      iter = 5e4, warmup = 5000, chains = 4, cores = 4, thin = 2,
      seed = 666, prior = all_priors)
## Compiling Stan program...
## Trying to compile a simple C file
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
## Start sampling
brms::mcmc_plot(mod_nonspatial_log, type = "trace") + theme_cowplot()
## No divergences to plot.

#check for agreement of chains
brms::mcmc_plot(mod_nonspatial_log, type = "dens_overlay") + theme_cowplot()

# plot posterior probabilities
brms::mcmc_plot(mod_nonspatial_log, type = "intervals",prob = 0.68, prob_outer = 0.95, variable = "^b_", regex = TRUE) + theme_cowplot()

pp_check(mod_nonspatial_log, ndraws = 500) + theme_cowplot() +  scale_x_continuous(limits = c(0,50)) # good fit to data

bayes_R2(mod_nonspatial_log)
##     Estimate  Est.Error      Q2.5     Q97.5
## R2 0.5499843 0.05630999 0.4216702 0.6392163
bres <- residuals(mod_nonspatial_log)[,"Estimate"]
d_mat = as.matrix(dist(df[,c("Lat", "Long")], diag=T, upper=T))
d_mat_inv <- 1/d_mat
d_mat_inv[which(d_mat_inv == Inf)] <- 0
ape::Moran.I(bres, d_mat_inv)
## $observed
## [1] 0.007473419
## 
## $expected
## [1] -0.01123596
## 
## $sd
## [1] 0.02295459
## 
## $p.value
## [1] 0.4150378
summary(mod_nonspatial_log)
##  Family: lognormal 
##   Links: mu = identity; sigma = identity 
## Formula: round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1 | Site_ID) 
##    Data: df (Number of observations: 90) 
##   Draws: 4 chains, each with iter = 50000; warmup = 5000; thin = 2;
##          total post-warmup draws = 90000
## 
## Group-Level Effects: 
## ~Site_ID (Number of levels: 22) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.11      0.05     0.02     0.22 1.00    34486    38424
## 
## Population-Level Effects: 
##                                             Estimate Est.Error l-95% CI
## Intercept                                       0.30      0.08     0.15
## LanduseDeveloped                                0.06      0.11    -0.15
## TyphoonPost                                     0.40      0.09     0.22
## Species_IDHorornis_diphone                      0.15      0.10    -0.05
## Species_IDOtus_elegans                         -0.19      1.42    -2.96
## LanduseDeveloped:TyphoonPost                   -0.21      0.11    -0.43
## LanduseDeveloped:Species_IDHorornis_diphone     0.08      0.12    -0.15
## LanduseDeveloped:Species_IDOtus_elegans        -0.19      1.42    -2.98
## TyphoonPost:Species_IDHorornis_diphone         -0.16      0.11    -0.38
## TyphoonPost:Species_IDOtus_elegans             -0.09      0.16    -0.40
##                                             u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                       0.45 1.00    81187    79497
## LanduseDeveloped                                0.27 1.00    80169    79551
## TyphoonPost                                     0.58 1.00    83773    81496
## Species_IDHorornis_diphone                      0.35 1.00    81547    82031
## Species_IDOtus_elegans                          2.60 1.00    87734    83733
## LanduseDeveloped:TyphoonPost                    0.01 1.00    82614    81457
## LanduseDeveloped:Species_IDHorornis_diphone     0.31 1.00    80730    81054
## LanduseDeveloped:Species_IDOtus_elegans         2.58 1.00    87807    82688
## TyphoonPost:Species_IDHorornis_diphone          0.06 1.00    81362    80980
## TyphoonPost:Species_IDOtus_elegans              0.22 1.00    75306    78622
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.24      0.02     0.20     0.29 1.00    54179    68818
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

Plot typhoon effect:

mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_TyphoonPost, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_TyphoonPost + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp) 
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","skyblue")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (typhoon effect)",
       y = "") + 
  cowplot::theme_minimal_grid()

bird detection spatial variability

bird detections - species effect

# prepare data
df<-tidy.spatial_bird %>%
  filter(response_group %in% 'Total_Var') # get pre vs post data for comparison
df2<-df
df2$Date<-df2$Date %>%  julian.Date() %>% as.numeric() # convert to numeric date format for model
df2$Date<-df2$Date - min(df2$Date) # scale date to start at zero for model

# split out time series for each species class separately
temp<-model.matrix(~ 0 + df2$Species)*df2$Date
date_Corv<-temp[,1]
date_Horo<-temp[,2]
date_Otus<-temp[,3]
rm(temp)

#hist(df$Stability) # looks lognormal
olm<-glm(Stability ~ 0 + Species + date_Corv + date_Horo + date_Otus,
         data = df2,family = gaussian(link = 'log')) # linear model

summary(olm)
## 
## Call:
## glm(formula = Stability ~ 0 + Species + date_Corv + date_Horo + 
##     date_Otus, family = gaussian(link = "log"), data = df2)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.39145  -0.31137  -0.06864   0.23009   2.86613  
## 
## Coefficients:
##                              Estimate Std. Error t value Pr(>|t|)    
## SpeciesCorvus_macrorhynchos 0.2944319  0.0983584   2.993  0.00312 ** 
## SpeciesHorornis_diphone     0.2368806  0.0839597   2.821  0.00528 ** 
## SpeciesOtus_elegans         1.1909561  0.0400509  29.736  < 2e-16 ***
## date_Corv                   0.0001205  0.0025663   0.047  0.96260    
## date_Horo                   0.0121436  0.0018460   6.578 4.36e-10 ***
## date_Otus                   0.0006172  0.0010304   0.599  0.54989    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.2997473)
## 
##     Null deviance: 501.199  on 199  degrees of freedom
## Residual deviance:  57.851  on 193  degrees of freedom
## AIC: 332.89
## 
## Number of Fisher Scoring iterations: 5
#plot(olm)

# get break points
Psi_1<-df$Date[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - df$Date[1] %>% julian.Date() %>% as.numeric()
Psi_2<-df$Date[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - df$Date[1] %>% julian.Date() %>% as.numeric()

## break-point model ##
os <- segmented(olm, 
                seg.Z = ~ date_Corv + date_Horo + date_Otus, # which variables to break
                psi = list(date_Corv=c(Psi_1,Psi_2),
                           date_Horo=c(Psi_1,Psi_2),
                           date_Otus=c(Psi_1,Psi_2)),
                control = seg.control(it.max = 0)) # it.max = 0 prevents bootstrap procedure (i.e. forces manual break-point)

AIC(os,olm) # break point model performs better
##     df      AIC
## os  13 337.9056
## olm  7 332.8869
## davies test of the change in slope after break points
davies.test(olm,seg.Z = ~ date_Corv,
            values = c(Psi_1,Psi_2)) # test for change in slope of forest sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Species + date_Corv + date_Horo + date_Otus ,   method = glm 
## model = gaussian , link = log , statist = lrt 
## segmented variable = date_Corv
## 'best' at = 30, n.points = 2, p-value = 0.6016
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_Horo,
            values = c(Psi_1,Psi_2)) # test for change in slope of developed sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Species + date_Corv + date_Horo + date_Otus ,   method = glm 
## model = gaussian , link = log , statist = lrt 
## segmented variable = date_Horo
## 'best' at = 30, n.points = 2, p-value = 0.3709
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_Otus,
            values = c(Psi_1,Psi_2)) # test for change in slope of developed sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Species + date_Corv + date_Horo + date_Otus ,   method = glm 
## model = gaussian , link = log , statist = lrt 
## segmented variable = date_Otus
## 'best' at = 37, n.points = 2, p-value = 0.6549
## alternative hypothesis: two.sided
summary(os)
## 
## Call:
## glm(formula = Stability ~ Species + date_Corv + date_Horo + date_Otus + 
##     U1.date_Corv + U2.date_Corv + U1.date_Horo + U2.date_Horo + 
##     U1.date_Otus + U2.date_Otus - 1, family = gaussian(link = "log"), 
##     data = mfExt)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.32267  -0.36387  -0.03511   0.20805   2.44537  
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)    
## SpeciesCorvus_macrorhynchos  0.3953437  0.1334299   2.963 0.003443 ** 
## SpeciesHorornis_diphone      0.0144594  0.1491537   0.097 0.922876    
## SpeciesOtus_elegans          1.1856549  0.0582577  20.352  < 2e-16 ***
## date_Corv                   -0.0077334  0.0077263  -1.001 0.318162    
## date_Horo                    0.0264756  0.0068424   3.869 0.000151 ***
## date_Otus                    0.0006354  0.0033142   0.192 0.848179    
## U1.date_Corv                 0.0337655  0.0340437   0.992 0.322563    
## U2.date_Corv                -0.0275707  0.0336930  -0.818 0.414231    
## U1.date_Horo                -0.0552909  0.0235015  -2.353 0.019679 *  
## U2.date_Horo                 0.0444937  0.0222013   2.004 0.046502 *  
## U1.date_Otus                 0.0047852  0.0140683   0.340 0.734133    
## U2.date_Otus                -0.0066243  0.0137481  -0.482 0.630486    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.2987036)
## 
##     Null deviance: 501.199  on 199  degrees of freedom
## Residual deviance:  55.857  on 187  degrees of freedom
## AIC: 337.91
## 
## Number of Fisher Scoring iterations: 6
# compare pre- and post-break acoustic index values
Break_results<-df %>% 
  filter(Period %in% c('Pre-typhoon','Post-typhoon')) %>% 
  group_by(Species,Period) %>% 
  summarise(Med=median(Stability),
            Lo_95=quantile(Stability,probs = 0.05),
            Up_95=quantile(Stability,probs = 0.95))
## `summarise()` has grouped output by 'Species'. You can override using the
## `.groups` argument.
Break_results$Period<-Break_results$Period %>% as.character() %>% parse_factor(levels = c('Pre-typhoon','Post-typhoon'))
Break_results$Species<-Break_results$Species %>% as.character() %>% parse_factor(levels = c('Corvus_macrorhynchos','Horornis_diphone','Otus_elegans'))

Plot results:

Sp_labs<-c('C. macrorhynchos','H. diphone','O. elegans')
names(Sp_labs)<-c('Corvus_macrorhynchos','Horornis_diphone','Otus_elegans')

plot1<-df %>% ggplot(aes(x = Date,
                  y = Stability,
                  alpha = Species)) +
  scale_alpha_manual(values = c(1,0.6,0.3)) +
#  scale_colour_manual(values = c("black","grey50","grey80")) +
  geom_vline(xintercept = df$Date[df$Period %in% 'Trami'][1],lty = 2) + 
  geom_vline(xintercept = df$Date[df$Period %in% 'Post-typhoon'][1],lty = 2) + 
  geom_line(show.legend = F) + 
  labs(x = "Time",
       y = "Species detection spatial variability") + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max())) 

plot2<-Break_results %>% ggplot(aes(x = Species,
                  y = Med,
                  ymin = Lo_95,
                  ymax = Up_95,
                  alpha = Species,
                  shape = Period)) +
  scale_alpha_manual(values = c(1,0.6,0.3)) +
#  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  geom_pointrange(position = position_jitterdodge(),
                  fatten = 5,
                  show.legend = F) + 
  labs(x = "Species",
       y = element_blank()) + 
  scale_x_discrete(labels = Sp_labs) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max()))

panel_a<-plot1 + plot2 + plot_layout(widths = c(3,1))
panel_a

Now check for landuse effect:

# prepare data
df<-tidy.spatial_bird %>%
  filter(response_group %in% c('Forest_Var','Developed_Var')) # get pre vs post data for comparison
df$response_group[df$response_group %in% 'Forest_Var']<-'Forest'
df$response_group[df$response_group %in% 'Developed_Var']<-'Developed'
colnames(df)[4]<-'Landuse'
df$Landuse<-df$Landuse %>% as.character() %>% parse_factor(levels = c('Forest','Developed')) # change levels for model
df$Stability[df$Species %in% 'Otus_elegans' & df$Landuse %in% 'Forest']<-df$Stability[df$Species %in% 'Otus_elegans' & df$Landuse %in% 'Developed'] # fix error in forest owl data (showing up as developed for some reason)
df$Stability[df$Species %in% 'Otus_elegans' & df$Landuse %in% 'Developed']<-NA # fix error in forest owl data
df2<-df
df2$Date<-df2$Date %>%  julian.Date() %>% as.numeric() # convert to numeric date format for model
df2$Date<-df2$Date - min(df2$Date) # scale date to start at zero for model

# split out time series for each species class separately
temp<-model.matrix(~ 0 + df2$Species * df2$Landuse)*df2$Date
date_Corv_for<-temp[,1]
date_Horo_for<-temp[,2]
date_Otus_for<-temp[,3]
date_Corv_dev<-temp[,4]
date_Horo_dev<-temp[,5]
rm(temp)

#hist(df$Stability) # looks lognormal
olm<-glm(Stability ~ 0 + Species + Landuse + date_Corv_for + date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev,
         data = df2,family = gaussian(link = 'log')) # linear model

summary(olm)
## 
## Call:
## glm(formula = Stability ~ 0 + Species + Landuse + date_Corv_for + 
##     date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev, 
##     family = gaussian(link = "log"), data = df2)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.06328  -0.29742  -0.06402   0.21754   1.56347  
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)    
## SpeciesCorvus_macrorhynchos  0.4530744  0.0661333   6.851 3.77e-11 ***
## SpeciesHorornis_diphone      0.4034000  0.0583292   6.916 2.53e-11 ***
## SpeciesOtus_elegans          0.7621943  0.0504132  15.119  < 2e-16 ***
## LanduseDeveloped            -0.3637955  0.0785195  -4.633 5.25e-06 ***
## date_Corv_for               -0.0055654  0.0019943  -2.791 0.005576 ** 
## date_Horo_for                0.0079596  0.0013982   5.693 2.83e-08 ***
## date_Otus_for                0.0006876  0.0012955   0.531 0.595955    
## date_Corv_dev                0.0111716  0.0023546   4.745 3.15e-06 ***
## date_Horo_dev               -0.0065366  0.0018524  -3.529 0.000479 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.2019162)
## 
##     Null deviance: 275.501  on 329  degrees of freedom
## Residual deviance:  64.613  on 320  degrees of freedom
##   (69 observations deleted due to missingness)
## AIC: 418.17
## 
## Number of Fisher Scoring iterations: 5
#plot(olm)

# get break points
Psi_1<-df$Date[df$Period %in% 'Trami'][1] %>%  julian.Date() %>% as.numeric() - df$Date[1] %>% julian.Date() %>% as.numeric()
Psi_2<-df$Date[df$Period %in% 'Post-typhoon'][1] %>%  julian.Date() %>% as.numeric() - df$Date[1] %>% julian.Date() %>% as.numeric()

## break-point model ##
os <- segmented(olm, 
                seg.Z = ~ date_Corv_for + date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev, # which variables to break
                psi = list(date_Corv_for=c(Psi_1,Psi_2),
                           date_Horo_for=c(Psi_1,Psi_2),
                           date_Otus_for=c(Psi_1,Psi_2),
                           date_Corv_dev=c(Psi_1,Psi_2),
                           date_Horo_dev=c(Psi_1,Psi_2)),
                control = seg.control(it.max = 0)) # it.max = 0 prevents bootstrap procedure (i.e. forces manual break-point)

AIC(os,olm) # break point model performs better
##     df      AIC
## os  20 421.9435
## olm 10 418.1682
## davies test of the change in slope after break points
davies.test(olm,seg.Z = ~ date_Corv_for,
            values = c(Psi_1,Psi_2)) # test for change in slope of forest sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Species + Landuse + date_Corv_for + date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev ,   method = glm 
## model = gaussian , link = log , statist = lrt 
## segmented variable = date_Corv_for
## 'best' at = 30, n.points = 2, p-value = 0.7488
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_Horo_for,
            values = c(Psi_1,Psi_2)) # test for change in slope of developed sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Species + Landuse + date_Corv_for + date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev ,   method = glm 
## model = gaussian , link = log , statist = lrt 
## segmented variable = date_Horo_for
## 'best' at = 30, n.points = 2, p-value = 0.2722
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_Otus_for,
            values = c(Psi_1,Psi_2)) # test for change in slope of developed sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Species + Landuse + date_Corv_for + date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev ,   method = glm 
## model = gaussian , link = log , statist = lrt 
## segmented variable = date_Otus_for
## 'best' at = 37, n.points = 2, p-value = 0.6868
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_Corv_dev,
            values = c(Psi_1,Psi_2)) # test for change in slope of forest sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Species + Landuse + date_Corv_for + date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev ,   method = glm 
## model = gaussian , link = log , statist = lrt 
## segmented variable = date_Corv_dev
## 'best' at = 37, n.points = 2, p-value = 0.2356
## alternative hypothesis: two.sided
davies.test(olm,seg.Z = ~ date_Horo_dev,
            values = c(Psi_1,Psi_2)) # test for change in slope of developed sites
## 
##  Davies' test for a change in the slope
## 
## data:  formula = Stability ~ 0 + Species + Landuse + date_Corv_for + date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev ,   method = glm 
## model = gaussian , link = log , statist = lrt 
## segmented variable = date_Horo_dev
## 'best' at = 37, n.points = 2, p-value = 0.3547
## alternative hypothesis: two.sided
summary(os)
## 
## Call:
## glm(formula = Stability ~ Species + Landuse + date_Corv_for + 
##     date_Horo_for + date_Otus_for + date_Corv_dev + date_Horo_dev + 
##     U1.date_Corv_for + U2.date_Corv_for + U1.date_Horo_for + 
##     U2.date_Horo_for + U1.date_Otus_for + U2.date_Otus_for + 
##     U1.date_Corv_dev + U2.date_Corv_dev + U1.date_Horo_dev + 
##     U2.date_Horo_dev - 1, family = gaussian(link = "log"), data = mfExt)
## 
## Deviance Residuals: 
##      Min        1Q    Median        3Q       Max  
## -1.01115  -0.29632  -0.04608   0.20484   1.58962  
## 
## Coefficients:
##                               Estimate Std. Error t value Pr(>|t|)    
## SpeciesCorvus_macrorhynchos  0.5281456  0.0891979   5.921 8.48e-09 ***
## SpeciesHorornis_diphone      0.2819640  0.0913602   3.086 0.002210 ** 
## SpeciesOtus_elegans          0.7572079  0.0728795  10.390  < 2e-16 ***
## LanduseDeveloped            -0.3012331  0.1178538  -2.556 0.011065 *  
## date_Corv_for               -0.0118111  0.0055460  -2.130 0.033988 *  
## date_Horo_for                0.0171096  0.0045190   3.786 0.000184 ***
## date_Otus_for                0.0006118  0.0041458   0.148 0.882769    
## date_Corv_dev                0.0053295  0.0076618   0.696 0.487206    
## date_Horo_dev               -0.0082786  0.0063805  -1.297 0.195434    
## U1.date_Corv_for             0.0241600  0.0275393   0.877 0.381008    
## U2.date_Corv_for            -0.0170674  0.0287538  -0.594 0.553232    
## U1.date_Horo_for            -0.0449296  0.0182538  -2.461 0.014385 *  
## U2.date_Horo_for             0.0406309  0.0182906   2.221 0.027045 *  
## U1.date_Otus_for             0.0059812  0.0175685   0.340 0.733750    
## U2.date_Otus_for            -0.0080399  0.0171463  -0.469 0.639472    
## U1.date_Corv_dev             0.0472932  0.0384173   1.231 0.219242    
## U2.date_Corv_dev            -0.0525663  0.0390245  -1.347 0.178961    
## U1.date_Horo_dev             0.0124560  0.0446125   0.279 0.780274    
## U2.date_Horo_dev            -0.0102703  0.0471741  -0.218 0.827797    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.1984008)
## 
##     Null deviance: 275.501  on 329  degrees of freedom
## Residual deviance:  61.504  on 310  degrees of freedom
## AIC: 421.94
## 
## Number of Fisher Scoring iterations: 6
# compare pre- and post-break acoustic index values
Break_results<-df %>% 
  filter(Period %in% c('Pre-typhoon','Post-typhoon')) %>% 
  group_by(Species,Landuse,Period) %>% 
  summarise(Med=median(Stability,na.rm = T),
            Lo_95=quantile(Stability,probs = 0.05,na.rm = T),
            Up_95=quantile(Stability,probs = 0.95,na.rm = T))
## `summarise()` has grouped output by 'Species', 'Landuse'. You can override
## using the `.groups` argument.
Break_results$Period<-Break_results$Period %>% as.character() %>% parse_factor(levels = c('Pre-typhoon','Post-typhoon'))
Break_results$Landuse<-Break_results$Landuse %>% as.character() %>% parse_factor(levels = c('Forest','Developed'))
Break_results$Species<-Break_results$Species %>% as.character() %>% parse_factor(levels = c('Corvus_macrorhynchos','Horornis_diphone','Otus_elegans'))

Plot results:

plot1<-df %>% ggplot(aes(x = Date,
                  y = Stability,
                  alpha = Species,
                  col = Landuse)) +
  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  scale_alpha_manual(values = c(1,0.6,0.3)) +
  geom_vline(xintercept = df$Date[df$Period %in% 'Trami'][1],lty = 2) + 
  geom_vline(xintercept = df$Date[df$Period %in% 'Post-typhoon'][1],lty = 2) + 
  geom_line(show.legend = F) + 
  labs(x = "Time",
       y = "Species detection spatial variability") + 
  theme_cowplot(12) + 
  theme(strip.background = element_rect(fill = 'white')) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max())) + 
  facet_grid(Species ~ .,
             labeller = labeller(Species = Sp_labs))

plot2<-Break_results %>% ggplot(aes(x = Species,
                  y = Med,
                  ymin = Lo_95,
                  ymax = Up_95,
                  alpha = Species,
                  col = Landuse,
                  shape = Period)) +
  scale_alpha_manual(values = c(1,0.6,0.3)) +
  scale_colour_manual(values = c("#29a62b","#a629a4")) +
  geom_pointrange(position = position_jitterdodge(),
                  fatten = 5,
                  show.legend = F) + 
  labs(x = 'Species',
       y = element_blank()) + 
  scale_x_discrete(labels = Sp_labs) + 
  theme_cowplot(12) + 
  ylim(c(df$Stability %>% min(),
         df$Stability %>% max()))

panel_b<-plot1 + plot2 + plot_layout(widths = c(3,1))
panel_b
## Warning: Removed 65 row(s) containing missing values (geom_path).
## Warning: Removed 2 rows containing missing values (geom_pointrange).

panel_a / panel_b
## Warning: Removed 65 row(s) containing missing values (geom_path).
## Warning: Removed 2 rows containing missing values (geom_pointrange).

** Do SAME BUT FOR DIFFERENT TIME HORIZONS BEFORE AND AFTER TYPHOONS - TO SHOW RESULTS DON’T DEPEND ON TIME BEFORE/AFTER TYPHOONS

Figure S2

Finally, compare different automatic filtering thresholds for species detection confidence. Test the mean species effect on Horonis_diphone under three confidence thresholds. NB: to speed this up, we’ll run 10x fewer iterations in the models.

Threshold = 0.5

dat_pre<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.5 & response_variable %in% 'Pre_mean') 
dat_post<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.5 & response_variable %in% 'Post_mean') 
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
# change levels for model
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Stability<-df$Stability+1 # try this to run lognormal model (cannot have zero values)

# set weakly informative priors
all_priors<-c(
  set_prior("normal(0, 2)",coef = "LanduseDeveloped"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:TyphoonPost"),
  set_prior("normal(0, 2)",coef = "Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "TyphoonPost"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDOtus_elegans"))

# Fit bayesian mixed effects model
mod_nonspatial_log <- 
  brm(data = df, family = lognormal(),
      round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + # used round() as poisson needs integers
        Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1|Site_ID),
      iter = 5e3, warmup = 500, chains = 4, cores = 4, thin = 2,
      seed = 666, prior = all_priors)
## Compiling Stan program...
## Start sampling
summary(mod_nonspatial_log)
##  Family: lognormal 
##   Links: mu = identity; sigma = identity 
## Formula: round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1 | Site_ID) 
##    Data: df (Number of observations: 90) 
##   Draws: 4 chains, each with iter = 5000; warmup = 500; thin = 2;
##          total post-warmup draws = 9000
## 
## Group-Level Effects: 
## ~Site_ID (Number of levels: 22) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.69      0.18     0.37     1.08 1.00     4387     6505
## 
## Population-Level Effects: 
##                                             Estimate Est.Error l-95% CI
## Intercept                                       3.58      0.32     2.94
## LanduseDeveloped                                0.26      0.44    -0.60
## TyphoonPost                                    -0.18      0.32    -0.80
## Species_IDHorornis_diphone                     -1.06      0.35    -1.76
## Species_IDOtus_elegans                         -0.46      1.43    -3.26
## LanduseDeveloped:TyphoonPost                   -0.41      0.38    -1.16
## LanduseDeveloped:Species_IDHorornis_diphone    -0.33      0.41    -1.12
## LanduseDeveloped:Species_IDOtus_elegans        -0.49      1.43    -3.28
## TyphoonPost:Species_IDHorornis_diphone         -1.25      0.39    -2.01
## TyphoonPost:Species_IDOtus_elegans             -0.11      0.55    -1.17
##                                             u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                       4.19 1.00     6665     7545
## LanduseDeveloped                                1.11 1.00     6387     7500
## TyphoonPost                                     0.45 1.00     8400     8296
## Species_IDHorornis_diphone                     -0.37 1.00     7949     7780
## Species_IDOtus_elegans                          2.34 1.00     8218     8330
## LanduseDeveloped:TyphoonPost                    0.35 1.00     8465     8083
## LanduseDeveloped:Species_IDHorornis_diphone     0.49 1.00     7827     8121
## LanduseDeveloped:Species_IDOtus_elegans         2.24 1.00     8215     8226
## TyphoonPost:Species_IDHorornis_diphone         -0.49 1.00     8137     7959
## TyphoonPost:Species_IDOtus_elegans              0.94 1.00     7646     8260
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.86      0.08     0.72     1.04 1.00     6321     7697
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
#Plot - Horornis #
mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_Species_IDHorornis_diphone, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_Species_IDHorornis_diphone + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp) 
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
Plot_50 <- mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","navajowhite")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (species effect)",
       y = "") + 
  cowplot::theme_minimal_grid()

Threshold = 0.75

dat_pre<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.75 & response_variable %in% 'Pre_mean') 
dat_post<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.75 & response_variable %in% 'Post_mean') 
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
# change levels for model
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Stability<-df$Stability+1 # try this to run lognormal model (cannot have zero values)

# set weakly informative priors
all_priors<-c(
  set_prior("normal(0, 2)",coef = "LanduseDeveloped"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:TyphoonPost"),
  set_prior("normal(0, 2)",coef = "Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "TyphoonPost"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDOtus_elegans"))

# Fit bayesian mixed effects model
mod_nonspatial_log <- 
  brm(data = df, family = lognormal(),
      round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + # used round() as poisson needs integers
        Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1|Site_ID),
      iter = 5e3, warmup = 500, chains = 4, cores = 4, thin = 2,
      seed = 666, prior = all_priors)
## Compiling Stan program...
## Trying to compile a simple C file
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
## Start sampling
summary(mod_nonspatial_log)
##  Family: lognormal 
##   Links: mu = identity; sigma = identity 
## Formula: round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1 | Site_ID) 
##    Data: df (Number of observations: 90) 
##   Draws: 4 chains, each with iter = 5000; warmup = 500; thin = 2;
##          total post-warmup draws = 9000
## 
## Group-Level Effects: 
## ~Site_ID (Number of levels: 22) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.78      0.17     0.50     1.16 1.00     4324     5764
## 
## Population-Level Effects: 
##                                             Estimate Est.Error l-95% CI
## Intercept                                       4.90      0.30     4.30
## LanduseDeveloped                                0.27      0.42    -0.56
## TyphoonPost                                    -0.18      0.25    -0.67
## Species_IDHorornis_diphone                     -1.16      0.29    -1.72
## Species_IDOtus_elegans                         -0.79      1.43    -3.63
## LanduseDeveloped:TyphoonPost                   -0.62      0.31    -1.23
## LanduseDeveloped:Species_IDHorornis_diphone    -0.41      0.33    -1.06
## LanduseDeveloped:Species_IDOtus_elegans        -0.82      1.43    -3.59
## TyphoonPost:Species_IDHorornis_diphone         -0.89      0.31    -1.49
## TyphoonPost:Species_IDOtus_elegans              0.24      0.44    -0.63
##                                             u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                       5.47 1.00     5984     7349
## LanduseDeveloped                                1.10 1.00     5313     6628
## TyphoonPost                                     0.33 1.00     8527     8219
## Species_IDHorornis_diphone                     -0.60 1.00     7613     8018
## Species_IDOtus_elegans                          1.98 1.00     7648     7714
## LanduseDeveloped:TyphoonPost                   -0.02 1.00     8397     8221
## LanduseDeveloped:Species_IDHorornis_diphone     0.24 1.00     8046     7814
## LanduseDeveloped:Species_IDOtus_elegans         2.04 1.00     7398     7625
## TyphoonPost:Species_IDHorornis_diphone         -0.28 1.00     8394     8137
## TyphoonPost:Species_IDOtus_elegans              1.09 1.00     8235     8093
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.68      0.06     0.57     0.81 1.00     6543     7496
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
#Plot - Horornis #
mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_Species_IDHorornis_diphone, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_Species_IDHorornis_diphone + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp) 
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
Plot_75 <- mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","navajowhite")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (species effect)",
       y = "") + 
  cowplot::theme_minimal_grid()

Threshold = 0.9

dat_pre<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.9 & response_variable %in% 'Pre_mean') 
dat_post<-tidy.stability_bird %>%
  filter(Cutoff %in% 0.9 & response_variable %in% 'Post_mean') 
dat_pre<-dat_pre[complete.cases(dat_pre),]
dat_post<-dat_post[complete.cases(dat_post),]
dat_pre$Typhoon = rep("Pre", nrow(dat_pre))
dat_post$Typhoon = rep("Post", nrow(dat_post))
df <- rbind(dat_pre, dat_post)
# change levels for model
df$Typhoon<-df$Typhoon %>% parse_character() %>% parse_factor(levels = c('Pre','Post'))
df$Landuse<-df$Landuse %>% parse_character() %>% parse_factor(levels = c('Forest','Developed'))
df$Stability<-df$Stability+1 # try this to run lognormal model (cannot have zero values)

# set weakly informative priors
all_priors<-c(
  set_prior("normal(0, 2)",coef = "LanduseDeveloped"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "LanduseDeveloped:TyphoonPost"),
  set_prior("normal(0, 2)",coef = "Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "Species_IDOtus_elegans"),
  set_prior("normal(0, 2)",coef = "TyphoonPost"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDHorornis_diphone"),
  set_prior("normal(0, 2)",coef = "TyphoonPost:Species_IDOtus_elegans"))

# Fit bayesian mixed effects model
mod_nonspatial_log <- 
  brm(data = df, family = lognormal(),
      round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + # used round() as poisson needs integers
        Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1|Site_ID),
      iter = 5e3, warmup = 500, chains = 4, cores = 4, thin = 2,
      seed = 666, prior = all_priors)
## Compiling Stan program...
## Trying to compile a simple C file
## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c
## clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/unsupported"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/BH/include" -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/src/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppParallel/include/"  -I"/Library/Frameworks/R.framework/Versions/4.2/Resources/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include '/Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:88:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:1: error: unknown type name 'namespace'
## namespace Eigen {
## ^
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/src/Core/util/Macros.h:628:16: error: expected ';' after top level declarator
## namespace Eigen {
##                ^
##                ;
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:13:
## In file included from /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Dense:1:
## /Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppEigen/include/Eigen/Core:96:10: fatal error: 'complex' file not found
## #include <complex>
##          ^~~~~~~~~
## 3 errors generated.
## make: *** [foo.o] Error 1
## Start sampling
summary(mod_nonspatial_log)
##  Family: lognormal 
##   Links: mu = identity; sigma = identity 
## Formula: round(Stability) ~ 1 + Landuse + Typhoon + Species_ID + Landuse:Typhoon + Landuse:Species_ID + Typhoon:Species_ID + (1 | Site_ID) 
##    Data: df (Number of observations: 90) 
##   Draws: 4 chains, each with iter = 5000; warmup = 500; thin = 2;
##          total post-warmup draws = 9000
## 
## Group-Level Effects: 
## ~Site_ID (Number of levels: 22) 
##               Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sd(Intercept)     0.80      0.17     0.51     1.19 1.00     3990     5853
## 
## Population-Level Effects: 
##                                             Estimate Est.Error l-95% CI
## Intercept                                       5.44      0.30     4.85
## LanduseDeveloped                                0.30      0.42    -0.52
## TyphoonPost                                    -0.18      0.24    -0.66
## Species_IDHorornis_diphone                     -1.02      0.27    -1.56
## Species_IDOtus_elegans                         -0.93      1.41    -3.69
## LanduseDeveloped:TyphoonPost                   -0.76      0.30    -1.34
## LanduseDeveloped:Species_IDHorornis_diphone    -0.42      0.32    -1.05
## LanduseDeveloped:Species_IDOtus_elegans        -0.93      1.41    -3.72
## TyphoonPost:Species_IDHorornis_diphone         -0.73      0.29    -1.31
## TyphoonPost:Species_IDOtus_elegans              0.43      0.42    -0.42
##                                             u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept                                       6.03 1.00     5267     6329
## LanduseDeveloped                                1.15 1.00     4802     5669
## TyphoonPost                                     0.29 1.00     7431     7359
## Species_IDHorornis_diphone                     -0.47 1.00     7323     7546
## Species_IDOtus_elegans                          1.85 1.00     7933     7593
## LanduseDeveloped:TyphoonPost                   -0.17 1.00     8144     7776
## LanduseDeveloped:Species_IDHorornis_diphone     0.22 1.00     8146     8082
## LanduseDeveloped:Species_IDOtus_elegans         1.86 1.00     7993     7655
## TyphoonPost:Species_IDHorornis_diphone         -0.16 1.00     7091     7662
## TyphoonPost:Species_IDOtus_elegans              1.26 1.00     7407     7348
## 
## Family Specific Parameters: 
##       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma     0.65      0.06     0.55     0.79 1.00     6292     7819
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
#Plot - Horornis #
mut_mod<-mod_nonspatial_log %>%
  spread_draws(b_Species_IDHorornis_diphone, r_Site_ID[Site_ID,]) %>%
  mutate(site_mean = b_Species_IDHorornis_diphone + r_Site_ID) # get posterior distribution data for plotting
mut_mod$sig<-0
for (i in 1:length(unique(mut_mod$Site_ID))) {
  temp<-mut_mod$site_mean[mut_mod$Site_ID %in% mut_mod$Site_ID[i]] %>% 
    quantile(c(0.05,0.95)) %>% # get 95% credible intervals
    sign() %>% # get sign of those intervals
    duplicated() # are the signs identical (no = zero-spanning)
  if(temp[2] %in% TRUE){ # if signs are identical (non-zero-spanning)
    mut_mod$sig[mut_mod$Site_ID %in% mut_mod$Site_ID[i]]<-1 # add significance indicator
  }
} # determine whether credible intervals span zero, and store as binary (to show in plot): 
rm(temp) 
mut_mod$sig<-mut_mod$sig %>% as.character() %>% parse_factor(levels = c('0','1')) # convert to factor
Plot_90 <- mut_mod %>%
  ggplot(aes(y = Site_ID %>% as.character %>% parse_factor(levels = Site_order), 
             x = site_mean, 
             fill = stat(x) > 0,
             shape = sig)) + 
  stat_halfeye(show.legend = F,slab_type = "pdf") +
  geom_vline(xintercept = 0, 
             linetype = "dashed") +
  scale_fill_manual(values = c("gray80","navajowhite")) +
  scale_shape_manual(values = c(21,8)) +
  labs(x = "Posterior draws (species effect)",
       y = "") + 
  cowplot::theme_minimal_grid()

Compare plots:

# plots #
plot_grid(Plot_50, Plot_75, Plot_90, 
          ncol = 3, align = "hv", 
          labels = c("Threshold: 0.5", "Threshold: 0.75", "Threshold: 0.9"))